コード ビハインド C# コードを使用して、DownloadFile.aspx ページからファイルを出力しようとしています。私は次のことを行います:
protected void Page_Load(object sender, EventArgs e)
{
string strFilePath = @"C:\Server\file";
string strFileName = @"downloaded.txt";
long uiFileSize = new FileInfo(strFilePath).Length;
using (Stream file = File.OpenRead(strFilePath))
{
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=\"" + strFileName + "\"");
Response.AddHeader("Content-Length", uiFileSize.ToString());
Response.OutputStream.CopyTo(file);
Response.End();
}
}
これは機能しますが、ファイルをダウンロードして保存すると、そのコンテンツは単なる HTML ページになります。
ここで何が間違っていますか?