UAD6 – Physical path to virtual
Simple util to take a physical path and gets its virtual equivalent.
public static string PhysicalPathToVirtual(string path) { if (HttpContext.Current != null && !String.IsNullOrEmpty(path)) { return "/" + path.Replace(HttpContext.Current.Server.MapPath("/"), "").Replace(@"\", "/"); } else return null; } public static string PhysicalPathToVirtual(HttpContext context, string path) { if (context != null && !String.IsNullOrEmpty(path)) { return "/" + path.Replace(context.Server.MapPath("/"), "").Replace(@"\", "/"); } else return null; } |
Leave a Reply