trying to Use App_Data to get to XML file  
Author Message
Trochon





PostPosted: ASMX Web Services and XML Serialization, trying to Use App_Data to get to XML file Top

I am using the following code:

DataSet mydata = new DataSet();

mydata.ReadXml("~/App_Data/sdn.xml");

But instead of going to the App_Data directory of my web site (hosted on IIS on my local machine for test purposes), I get the error:

System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\WINDOWS\system32\~\App_Data\sdn.xml'.

Is there something I am missing If I put the file into a different path and reference the path directly, the program works fine, but I need the service to look into the correct app_data directory to deploy to a remote web server.



.NET Development18  
 
 
Saju Mathew





PostPosted: ASMX Web Services and XML Serialization, trying to Use App_Data to get to XML file Top

You should use the physical path while reading from a file.

DataSet mydata = new DataSet();

mydata.ReadXml(Server.MapPath("~/App_Data/sdn.xml"));

Hope this will help you.


 
 
Dragons And Owls





PostPosted: ASMX Web Services and XML Serialization, trying to Use App_Data to get to XML file Top

This helped me. Thank you.

Note in ASP 2.0 I had to use slight variant:

Code Block

System.Web.Hosting.HostingEnvironment.MapPath(...)