An important concept in managing path conversions is the application path. An ASP.NET application resides in a folder at either the root of a website or a subfolder. In order to have a portable web application, you don't want to hard code URLs in the application. All URLs should be essentially application relative.
But this means we need to programmatically determine the application path. URLs should be coded as follows:
Portable URLs
Contentsstring url = PathHelper.AppPath + "folder/page.aspx";
The PathHelper.AppPath Method
Contents/// <summary>
///
///
///
///
/// </summary>
public static string AppPath
{
get
{
string path = HttpContext.Current.Request.ApplicationPath;
if (path == "")
return "/";
if (path[path.Length-1] != '/')
path += "/";
return path;
}
}
Listing of Various Conversion Methods in PathHelper class
Using the PathHelper Class - Get path type
Contentsstring path = TextBox1.Text.Trim();
bool isPhysical = PathHelper.IsPhysicalPath(path);
bool isAbsolute = PathHelper.IsAbsolutePath(path);
bool isVirtual = PathHelper.IsVirtualPath(path);
bool isApplication = PathHelper.IsApplicationPath(path);
Sample output of PathHelper demo in the download
Credits
ContentsCredit goes to Matt Bell for the initial version of this class.
Back to Top