#region License
// (c) Intergen.
// This source is subject to the Microsoft Public License (Ms-PL).
// Please see http://go.microsoft.com/fwlink/?LinkID=131993 for details.
// All other rights reserved.
#endregion
using System;
using System.Text;
using System.IO;
using System.Web;
using System.Web.Hosting;
namespace Utilities.IO
{
public class FileUtils
{
public static string MapPath(string path)
{
if (Path.IsPathRooted(path))
{
return path;
}
else if (HostingEnvironment.IsHosted)
{
return HostingEnvironment.MapPath(path);
}
else if (VirtualPathUtility.IsAppRelative(path))
{
string physicalPath = VirtualPathUtility.ToAbsolute(path, "/");
physicalPath = physicalPath.Replace('/', '\\');
physicalPath = physicalPath.Substring(1);
physicalPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, physicalPath);
return physicalPath;
}
else
{
throw new Exception("Could not resolve non-rooted path.");
}
}
}
}
|