Showing posts with label extension method. Show all posts
Showing posts with label extension method. Show all posts

Sunday, April 19, 2015

Getting relative virtual path from physical path asp net c#

var relativePath = "/" + physicalPath.Replace(HttpContext.Current.Request.PhysicalApplicationPath, String.Empty).Replace("\\""/");
Or use the extension method
/// <summary>
/// Get relative path from physical path
/// </summary>
/// <param name="di">DirectoryInfo</param>
/// <returns></returns>
public static string GetRelativePath(this DirectoryInfo di)
{
 return "/" + di.FullName.Replace(HttpContext.Current.Request.PhysicalApplicationPath, String.Empty).Replace("\\""/");
}