注册 登录
编程论坛 ASP.NET技术论坛

关于写文件下载的问题

yinniannian 发布于 2011-08-25 11:40, 496 次点击
小弟菜鸟,我想写一个文件下载的程序,现在功能已经实习,代码如下

int index = Convert.ToInt32();//取得当前行
FileInfo downLoadFile = new FileInfo(GridView1.Rows[index].Cells[1].Text);
Response.ContentType = "application/octet-stream";
string fileName = HttpUtility.UrlEncode(GridView1.Rows[index].Cells[0].Text, System.Text.Encoding.UTF8);//防止中文名称时的乱码
Response.AddHeader("Content-Disposition", "attachment;filename=" + fileName);
Response.AppendHeader("Content-length", downLoadFile.Length.ToString());
Response.WriteFile(downLoadFile.FullName);
Response.Flush();
Response.End();

但是对Response的AddHeader不是太了解,望高手指教
1 回复
#2
heliyi2011-08-25 23:23
指定文件名称,告诉浏览器文件大小
1