public static string GetMapPath(string virtualPath)
{
if (virtualPath == null)
{
return "";
}
else if (virtualPath.StartsWith("~/"))
{
return virtualPath.Replace("~/", AppDomainAppPath).Replace("/", "\\");
}
else
{
return Path.Combine(AppDomainAppPath, virtualPath.Replace("/", "\\"));
}
}
在 String strPath = System.Web.HttpContext.Current.Server.MapPath("test.txt");
string strPath=Server.MapPath("test.txt")
在MVC中 controller里,使用这个 Server.GetMapPath("~/ImagesFile/");