If your project doesn't work, look for the part that you didn't think was important. --Arthur Bloch
Welcome to my blog and project site for Microsoft.NET development.

I've been a full time .NET developer for ten years, but I didn't start my professional life as a programmer ... more
Share/Print this page:

How do I get the application path in an ASP.NET application?

And convert it from a virtual path to a physical path

By steve on February 13, 2007.
Updated on January 22, 2012.
Viewed 86,540 times (0 times today).
Article TypesLanguage ElementsTechnologies
SnippetConversionsASP.NET

Summary

How do I get the application path in an ASP.NET application?

Retrieve the application path

string appPath = HttpContext.Current.Request.ApplicationPath;

This property returns the virtual application path.

An empty string indicates that the application is at the root of the website.

Other examples might be:

/c4 /myapplication /myapps/AppNumberOne

Convert virtual application path to a physical path

string physicalPath = HttpContext.Current.Request.MapPath(appPath);


Examples:

C:\inetpub\wwwroot\myweb\c4 C:\inetpub\wwwroot\myweb\myapplication C:\inetpub\wwwroot\myweb\myapps/AppNumberOne

Back to Top

User Comments (8)

Posted 2009 Jun 11 16:33 PM. reply
I use this:

System.Web.HttpContext.Current.Server.MapPath("~/")

Gabe
Replied 2011 Dec 22 03:48 AM by ali. reply
that was my problem too.you are my man,tanx a lot
Posted 2010 Jun 16 13:23 PM. reply
This worked like a charm, Thank you !

Alpa
Posted 2010 Oct 19 03:45 AM. reply
nice 1

Isha
Posted 2011 Nov 30 04:21 AM. reply
Thnx a lot..... :)

Prateek Gupta
Posted 2011 Dec 22 03:47 AM. reply
tanx a lot

ali
Posted 2012 Jan 19 00:55 AM. reply
Thanks so very lot. You saved my day! :)

Asit
Posted 2012 Jan 20 04:46 AM. reply
Thanks a lot for saving my day. :)

Mr. Phyo [Myanmar]
Post Your Comment
  You may post without logging in or login here.
Display Name: Required.
Email: Required. Will not be shown. Used for identicon.
Comment:
Allowed tags: <quote></quote>, <code></code>, <b></b>, <i></i>, <u></u>, <red></red>
 
   Please type text as shown in the image at left.