Question:
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.
Answer:
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.