用下面的方法能实现下载功能。不过我在后面加跳转页面或者让另一个按钮
this.Button2.Enabled = true; 也会失败。有什么解决方法么?
在线急等。。protected void Button1_Click(object sender, EventArgs e)
{
string fileName = "aaa.txt";//客户端保存的文件名
string filePath = Server.MapPath("DownLoad/aaa.txt");//路径 //以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
this.Button2.Enabled = true;
}
this.Button2.Enabled = true; 也会失败。有什么解决方法么?
在线急等。。protected void Button1_Click(object sender, EventArgs e)
{
string fileName = "aaa.txt";//客户端保存的文件名
string filePath = Server.MapPath("DownLoad/aaa.txt");//路径 //以字符流的形式下载文件
FileStream fs = new FileStream(filePath, FileMode.Open);
byte[] bytes = new byte[(int)fs.Length];
fs.Read(bytes, 0, bytes.Length);
fs.Close();
Response.ContentType = "application/octet-stream";
//通知浏览器下载文件而不是打开
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
this.Button2.Enabled = true;
}
解决方案 »
- 下拉框弹出树形菜单
- asp.net内容页中加入CSS和javascript后总是提示缺少对象,在线等!
- 关于关闭所有IE时,用户自动退出
- asp.net c#里怎么调用中科院那套分词NICTCLAS(c++),我的代码可以运行,但不是很稳定。总是崩溃
- 急!!!各位高手怎样在SQL中更新,插入uniqueidentifier(GUID)数据
- (.NET重大问题)关于TreeView与DataGrid的,如何不刷新页面
- 在xp sp2下什么都装了,就是无法显示.aspx文件.请教你们
- 菜鸟问题,求教!
- 如何用TableRow同时返回多行数据?急!
- 请问能否在datagrid中实现数据统计功能?
- ASP.NET 数据插入有问题~~~急急急~~~
- 请各位帮忙一下
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
这三行到底做了什么么?
你要实现页面跳转,可以把页面跳转的代码写在Response.End这句的前面,就能成功执行了