Created
July 11, 2012 15:19
-
-
Save JayDouglass/3091084 to your computer and use it in GitHub Desktop.
Physical path to website relative path ASP.NET
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static partial class FileInfoExtensions | |
{ | |
public static string ToWebSiteRelativePath(this FileInfo fileInfo) | |
{ | |
var applicationPhysicalPath = HostingEnvironment.ApplicationPhysicalPath; | |
var filePhysicalPath = fileInfo.FullName; | |
if (filePhysicalPath.StartsWith(applicationPhysicalPath) == false) | |
throw new ArgumentOutOfRangeException(filePhysicalPath + " is not within application physical path: " + applicationPhysicalPath); | |
return filePhysicalPath.Replace(applicationPhysicalPath, HostingEnvironment.ApplicationVirtualPath + "/").Replace("\\", "/"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment