C# and returning relative application path

  • Thread starter Thread starter Yin99
  • Start date Start date
Y

Yin99

The two lines here are returning exactly what I'm looking for;
Problem is they only work in the .aspx page's "code behind" for that
page.

string path1 = Page.MapPath("~/");
string path2 = Server.MapPath("~/");

How do I get this info from a .cs custom class in the \app_code
folder? (e.g. just a stand alone class with no associated page?) I am
not having any luck finding answer. Thanks,

Yin
 
Yin,

You can use the HttpContext for the current thread:

// Map the current path:
string path2 = HttpContext.Current.Server.MapPath("~/");
 
How do I get this info from a .cs custom class in the \app_code
folder? (e.g. just a stand alone class with no associated page?) I am
not having any luck finding answer. Thanks,

HttpContext.Current.Server.MapPath


Mattias
 
Back
Top