「〜/ Uploads /Images/」をFileStreamを作成できる絶対パスに変換しようとしています。VirtualPathUtilityとPath.Combineを試しましたが、正しいパスが得られないようです。私が得た最も近いものはVirtualPathUtility.ToAppRelativeでしたが、それはC:の直接の子としてのファイルの場所にすぎませんでした。
これを行う方法が必要です。
「〜/ Uploads /Images/」をFileStreamを作成できる絶対パスに変換しようとしています。VirtualPathUtilityとPath.Combineを試しましたが、正しいパスが得られないようです。私が得た最も近いものはVirtualPathUtility.ToAppRelativeでしたが、それはC:の直接の子としてのファイルの場所にすぎませんでした。
これを行う方法が必要です。
あなたは方法を探していMapPath
ます。
// get the path in the local file system that corresponds to ~/Uploads/Images
string localPath = HttpContext.Current.Server.MapPath("~/Uploads/Images/");
Path.Combineと一緒に使用して、ファイルパスを作成します。
string fileName = Path.Combine(
HttpContext.Current.Server.MapPath("~/Uploads/Images/"),
"filename.ext");
using (FileStream stream = File.OpenRead(fileName))
{
// read the file
}