質問

私はからの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
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top