仮想ディレクトリをイメージにマップしない限り、クライアントブラウザはイメージの場所を決して知りません。ドライブをマップするのにServer.MapPath()
などを使用することはできません。
アプリケーション仮想ディレクトリ以外のファイルにアクセスするには、HttpHandlerを使用する必要があります。
Show Images from outside of ASP.NET Application
私は次のようにこれについてゴーグル後に得ているもう一つのアプローチ:
をあなたがファイルにアクセスしようとすることができるので、多くの関連問題へのスレッド次
チェック外部アプリケーションの仮想ディレクトリ。十分な許可をフォルダ/ファイルに注意する必要があります。あなたのウェブサイト内の画像にアクセスするための
次のことができ、あなたは次のリンクをチェックすることができます
Displaying images that are stored outside the Website Root Folder
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["FileName"] != null)
{
try
{
// Read the file and convert it to Byte Array
string filePath = "C:\\images\\";
string filename = Request.QueryString["FileName"];
string contenttype = "image/" +
Path.GetExtension(Request.QueryString["FileName"].Replace(".","");
FileStream fs = new FileStream(filePath + filename,
FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
//Write the file to response Stream
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.ContentType = contenttype;
Response.AddHeader("content-disposition", "attachment;filename=" + filename);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
catch
{
}
}
}
・ホープこのヘルプを。
Thak you so much ..... –