Converting a URI path to a relative file system path in .NET

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);
}

Leave a Comment