How do I convert an absolute or relative URI path (e.g. /foo/bar.txt
) to a (segmentwise) corresponding relative file system path (e.g. foo\bar.txt
) in .NET?
My program is not an ASP.NET application.
Have you already tried Server.MapPath
?
or Uri.LocalPath
property? Something like following :
string uriString = "file://server/filename.ext";
// Lesson learnt - always check for a valid URI
if(Uri.IsWellFormedUriString(uriString))
{
Uri uri = new Uri(uriString);
Console.WriteLine(uri.LocalPath);
}