Is there an opposite to Server.Mappath?
-
Hi, i was coding a small wen util to manage files on a webserver, and i needed a function do get the url from a file with a absolute path. Ex file : "c:\inetpub\wwwroot\funnyWeb\bad.txt" wich translate to "/funnyweb/bad.txt" is there a function build in asp.net that does that?
-
Hi, i was coding a small wen util to manage files on a webserver, and i needed a function do get the url from a file with a absolute path. Ex file : "c:\inetpub\wwwroot\funnyWeb\bad.txt" wich translate to "/funnyweb/bad.txt" is there a function build in asp.net that does that?
Hi there, From what I know, there is no public method like you say, however, you can write your own method. You first need to get the physical path of the application directory, then you can easily to convert a physical path to a virtual path. The sample code is something like this:
private string MapVirtualPath(string physicalPath)
{
string baseDir = HttpRuntime.AppDomainAppPath;
string virtualPath = "";
if(physicalPath.IndexOf(baseDir) >= 0)
{
string text1 = physicalPath.Substring(baseDir.Length);
text1 = text1.Replace("\\", "/");
virtualPath = HttpRuntime.AppDomainAppVirtualPath + "/" + text1;
}return virtualPath;
}