ahm*_*md0 3 c# asp.net web-applications download
我正在尝试使用代码隐藏的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();
}
}
Run Code Online (Sandbox Code Playgroud)
这是有效的,但是当文件被下载并保存时,其内容只是一个HTML页面.
我在这做错了什么?
| 归档时间: |
|
| 查看次数: |
1589 次 |
| 最近记录: |