views:

63

answers:

2

I'm trying to start out with LinqtoXml. I have added (I think) the right namespaces

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

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

Please help.

+2  A: 

Try this:

XElement contactsFromFile =
        XElement.Load( Server.MapPath( "~/App_Data/test.xml" ) );
tvanfosson
+1  A: 

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

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