Reputation: 742
I'm looking for a way to convert FQDN path: http://myserver.mydomain.com/mysite/myvirtualfolder/somefile.txt to physical path: c:\some\folder\somefile.txt.
My C# code is running on the same host where the IIS virtual Folder and IIS are located.
Is there any way to make such translation?
Upvotes: 1
Views: 59
Reputation: 25361
You can use the MapPath
method. If you use it in the ode-behind file for a web page:
string path = Server.MapPath("/mysite/myvirtualfolder/somefile.txt");
If you use it within a class that is not in the code-behind file:
string path = HttpContext.Current.Server.MapPath("/mysite/myvirtualfolder/somefile.txt");
Upvotes: 1