public static string GetPhysicalFilePath(string filePath)
{
string calculatedFilePath = null;
// Make sure it isn't a drive reference like "c:\blah" or a UNC name like "\\machine\share"
if ((filePath.IndexOf(":\\") != -1) || (filePath.IndexOf("\\\\") != -1))
calculatedFilePath = filePath;
else
{
if (HostingEnvironment.IsHosted)
{
calculatedFilePath = HostingEnvironment.MapPath(filePath);
}
else
{
filePath = filePath.Replace('/', Path.DirectorySeparatorChar).Replace("~", "");
calculatedFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath);
}
}
return calculatedFilePath;
}