Save XML File in Project Folder c# entity-framework xml


    XElement contactsFromFile = XElement.Load("App_Data/EmployeeFinList.xml");
    var xEle = new XElement("Employees",
        from emp in ListFromBasicPay
        select new XElement("Employee",
            new XAttribute("EmpID", emp.employee_personal_id),
            new XElement("GrandTotal", emp.grandTotal),
            new XElement("Housing", emp.housing),
            new XElement("BasePay", emp.base_pay),
            new XElement("XchangeRate", emp.Exchange_rate)));


    Debug.WriteLine("Converted to XML");
catch (Exception ex)

I want to save the xml file in a folder i created in my project. I will then use that xml file created in my folder and read and write from it. Any idea how to do it?

2/25/2013 5:21:36 PM

Popular Answer

Use System.Reflection.Assembly.GetExecutingAssembly().Location To get the full path of you assembly, Combine that with System.IO.Path.GetDirectoryName().

That would be like:

String path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);

xEle.Save(path + @"\myfilename.xml");

Though you should note that if your application is installed in C:\Program Files for example, you'll need some sort of elevation permissions to be able to write there depending on the security settings of the machine your app has been deployed on. It is best to always have a work directory in some other location like (Application Data) for example..

2/25/2013 5:48:57 PM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow