最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
asp.net 文件下载代码
时间:2010-08-05 编辑:简简单单 来源:一聚教程网
asp教程.net 文件下载代码
response.clear();
response.buffer = true;
response.contenttype="application/vnd.ms-excel";
response.addheader("content-disposition", "attachment; filename=billinginformation_"+this.ddl_mode.selectedvalue+"("+system.datetime.now.tostring("yyyymmdd")+").csv");
response.contentencoding=system.text.encoding.utf7;
response.charset="";
response.write("export excel file to clients sample");
response.end();
datatable filedt = filedao.getfilebyid(fileid);
byte[] filebytes = (byte[])filedt.rows[0]["filedata"];
string originalfilename = filedt.rows[0]["filename"].tostring();
string randomfilename = guid.newguid().tostring();
//下载到磁盘
string filefullpath = this.server.mappath("~/temp/" + randomfilename);
file.writeallbytes(filefullpath, filebytes);
//发送至客户端
response.clear();
response.clearcontent();
response.clearheaders();
response.contentencoding = system.text.encoding.getencoding("utf-8");
response.addheader("content-disposition", "attachment;filename=" + httputility.urlencode(originalfilename, system.text.encoding.utf8));
response.addheader("content-transfer-encoding", "binary");
response.contenttype = "application/octet-stream";
response.writefile(filefullpath);
response.flush();
//删除磁盘上的文件
if (file.exists(filefullpath))
file.delete(filefullpath);
response.end();
相关文章
- asp.net实现服务器文件下载到本地的方法 03-16
- ASP.NET调用jarsigner.exe失败:系统找不到指定的文件 12-05
- ASP.NET实现文件断点续传代码 06-06
- asp.net中Silverlight文件操作 02-01
- asp.net Global.asax文件与HttpApplication详解 05-10
- asp.net实现 文件断点续传的功能 01-25