我想将此物理路径转换"C:\bla\bla\Content\Upload\image.jpg"
为服务器路径,例如"/Content/Upload/image.jpg"
.
我怎样才能做到这一点 ?
我想将此物理路径转换"C:\bla\bla\Content\Upload\image.jpg"
为服务器路径,例如"/Content/Upload/image.jpg"
.
我怎样才能做到这一点 ?
你可以使用类似的东西:
public static class Extensions {
public static string RelativePath(this HttpServerUtility utility, string path, HttpRequest context)
{
return path.Replace(context.ServerVariables["APPL_PHYSICAL_PATH"], "/").Replace(@"\", "/");
}
}
你打电话给
Server.RelativePath(path, Request);
您可以执行以下操作来获取相对路径。
String filePath = @"C:\bla\bla\Content\Upload\image.jpg";
String serverPath = Request.PhysicalPath;
String relativePath = filePath.Substring(serverPath.Length, filePath.Length - serverPath.Length);