"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);