Sai Stuff to Developers

May 3, 2012

Finding Full Qualified Path for ASP.NET App_Data Folder

Filed under: DotNet — tosaik @ 12:06 pm
Tags: ,

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 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 🙂

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: