CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

怎么下载文件??

楼主bhys(碧海银沙)2003-12-01 17:47:04 在 .NET技术 / ASP.NET 提问

怎么下载文件,文件不是压缩格式.  
  Response.AddHeader("Content-Disposition",   "attachment;   filename="   +   HttpUtility.UrlEncode(scfilename,   System.Text.Encoding.UTF8))  
  Response.WriteFile(filepath)  
  Response.End()  
  下面的程序有点问题.下载时弹出的信息不正确.下载文本文件时会自动加一串代码进去,怎么解决.. 问题点数:20、回复次数:4Top

1 楼denny510(小单尼)回复于 2003-12-01 17:54:57 得分 5

呵呵,一个土办法:Response.redirect("......../aa.txt")  
  不过,文本文件会被打开的,  
  zip等文件,则会自动弹出windows下载工具Top

2 楼shang515(天天向上)回复于 2003-12-01 17:57:11 得分 8

看看这个  
  http://expert.csdn.net/Expert/TopicView1.asp?id=2513663Top

3 楼bhys(碧海银沙)回复于 2003-12-01 18:14:51 得分 0

我要下载的文件不是压缩格式呀Top

4 楼gasover(无尽)回复于 2003-12-01 18:57:26 得分 7

string   path   =   Server.MapPath(Request.Params["File"]);  
  System.IO.FileInfo   file   =   new   System.IO.FileInfo(path);  
   
  //   clear   the   current   output   content   from   the   buffer  
  Response.Clear();  
  //   add   the   header   that   specifies   the   default   filename   for   the   Download/SaveAs   dialog  
  Response.AddHeader("Content-Disposition",   "attachment;   filename="   +   file.Name);  
  //   add   the   header   that   specifies   the   file   size,   so   that   the   browser  
  //   can   show   the   download   progress  
  Response.AddHeader("Content-Length",   file.Length.ToString());  
  //   specify   that   the   response   is   a   stream   that   cannot   be   read   by   the  
  //   client   and   must   be   downloaded  
  Response.ContentType   =   "application/octet-stream";  
  //   send   the   file   stream   to   the   client  
  Response.WriteFile(file.FullName);  
  //   stop   the   execution   of   this   page  
  Response.End();  
  Top

相关问题

  • flash文件怎么下载?
  • 下载的iso文件怎么用。
  • 文件下载怎么实现?
  • 文件名有空格,怎么下载?
  • 这个asp文件怎么不能下载文件呢?
  • Response.BinaryWrite 方法怎么设置下载文件的 文件名
  • 公司里不能下载大文件怎么办才能下载大文件??
  • 文件下载……
  • 下载文件
  • 文件下载

关键词

  • 文件
  • 下载
  • response
  • filename
  • content

得分解答快速导航

  • 帖主:bhys
  • denny510
  • shang515
  • gasover

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo