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.
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.
XmlDocument(System.IO.Path.Combine(<strong>AppDomain.CurrentDomain.GetData(“DataDirectory”)</strong>,”abc.xml”));
Thats it….. Happy Coding
Maheshkumar S Tiwari edited Original. Comment: Added Tags and minor edit
Thanks for this shortcut. I will be using this little tip!