I was looking for something like Server.MapPath in the ASP.NET realm to convert the output of Assembly.GetExecutingAssembly().CodeBase into a file path with drive letter.
I looked for an answer a lot, and the most popular answer is using Uri.LocalPath. But System.Uri fails to give correct LocalPath if the Path contains “#”. Details are here.
My solution is:
private static string ConvertUriToPath(string fileName)
{
Uri uri = new Uri(fileName);
return uri.LocalPath + Uri.UnescapeDataString(uri.Fragment).Replace('/', '\\');
}