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.
- App_Data is essentially a storage point for file-based data store like .mdb, .mdf, .xls, .csv, .xml etc.., .
- It should not be viewable 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:
XmlDocument xdoc = new XmlDocument(“~/App_Data/abc.xml”);
and now i dont want to hardcode 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.
XmlDocument xdoc = new XmlDocument(System.IO.Path.Combine(AppDomain.CurrentDomain.GetData(“DataDirectory”),”abc.xml”));
Thats it….. Happy Coding 🙂