Caveman's Blog

My commitment to learning.

ASP.Net MapPath

leave a comment »


Writing code in  a web application with not access to HttpContext and still need to map to a folder in the website? No problem.. you can use the System.Web.Hosting.HostingEnvironment.MapPath function.


//This is how you would map if you had access to the HttpContext object

System.Web.HttpContext.Current.Server.MapPath("~/App_Data/data.xml");

//and here is how you would map if you do not have access to the HttpContext object

System.Web.Hosting.HostingEnvironment.MapPath("~/App_Data/data.xml");

Advertisements

Written by cavemansblog

August 11, 2009 at 4:52 pm

Posted in ASP.Net, Sudheer Reddy Battula

Tagged with

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

%d bloggers like this: