My Technical Notes

Wednesday, 13 August 2014

ASP.NET: Getting File System Path and Resolving Virtual Paths

To get the directory of the base directory, we can call:

var phys = System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath;

This is equivalent to:

var phys = System.Web.Hosting.HostingEnvironment.MapPath("~/");

To resolve a virtual path to an http path that the client can use, we do:

var defaultPath = System.Web.VirtualPathUtility.ToAbsolute("~/Default.aspx");

No comments: