Recently I had a requirement to add and use some xml files in my application and i pleased these xml files in ASP.NET special folder App_Data.

As we know the benefits of adding this folder in our application or for shortly I described in below couple of points.

  1. App_Data is essentially a storage point for file-based data store like .mdb, .mdf, .xls, .csv, .xml etc.., .
  2. It should not be view-able by the web and is a place for the web app to store and read data from.

And now  i need to map that xml file(s) so that i can get/set some data to it, for this as commonly need to get it though their respective path like the below:

1.XmlDocument xdoc = new XmlDocument(“~/App_Data/abc.xml”);

And now I don't want to hard code the path as shown above, for this i searched the entire BCL (Base Class Libraries) because App_Data is a special folder creating by ASP.NET so it is treated as a special folder. And finally I got the solution and below the code through which I can get fully qualified path for our App_Data folder from any place with in our application.

1.XmlDocument xdoc = new XmlDocument(System.IO.Path.Combine(<strong>AppDomain.CurrentDomain.GetData(“DataDirectory”)</strong>,”abc.xml”));

 See Also

That's it….. Happy Coding :)