How do I add an xml file to my project?

I am trying to start with LinqtoXml. I added (I think) the correct namespaces

XElement contactsFromFile = XElement.Load("App_Data/test.xml");

      

Doesn't work ... I'm getting "Couldn't find part of the path" C: \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ Common7 \ IDE \ App_Data \ test.xml '"error ...

Please, help.

+2


source to share


2 answers


Try the following:



XElement contactsFromFile =
        XElement.Load( Server.MapPath( "~/App_Data/test.xml" ) );

      

+2


source


There is a system property "HostingEnvironment.ApplicationPhysicalPath" which gives you the root directory where your application is deployed. I think you should do something like this:



HostingEnvironment.ApplicationPhysicalPath + "/App_Data/text.xml"

      

+1


source







All Articles