All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
无刷新仿google波形扭曲彩色Asp.net验证码_[Asp.Net教程]
asp.net2.0服务器控件之LinkButton控件
在Visual,C#中使用XML之编写XML_[Asp.Net教程]
Delphi 7功能强大的数据库访问技术
VS2005+SQL2005,ASP.NET2.0数据库连接_[Asp.Net教程]
SQL初学者教程:学会使用SQL SELECT 语句_[SQL Server教程]
该学Java或.NET?_[Asp.Net教程]
实例研究PHP函数isset和empty的区别_php资料_编程技术
页面第一次打开即给用户异步提示之Asp.net,Ajax延迟加载UpdatePanel_[Asp.Net教程]
C#中窗体继承的应用
Reading number is top 10 pictures
Parking technology is great, that give you the keys can't stolen
A man's favorite things3--ZhouWeiTong
Soong ching ling's former residence2
这才叫绝色美女2
Small QiShu -- ShuangShuangPan1
Most cow mistress ZhaoGongXia face exposure
A man's favorite things7
Chinese paper-cut grilles art appreciation3
做运动的校花1
穷哥们向美女求婚攻略
Download software ranking
Desire a peach blossom
致我们终将逝去的青春
C#程序员参考手册
实战黑客不求人
Boxer vs Yellow1
Ashlynn Video3
C#COM编程指南
Boxer Classic video3
dreamweaver8中文版
变速齿轮3.26
归海一刀 published in(发表于) 2014/1/30 1:22:24 Edit(编辑)
asp.net显示下载提示的下载网页程序_[Asp.Net教程]

asp.net显示下载提示的下载网页程序_[Asp.Net教程]

asp.net显示下载提示的下载网页程序_[Asp.Net教程]
网站制作经常要开发下载文件的功能,下面三种下载文件的办法:
1、asp实现下载的代码
<%
filename = Request.QueryString("FileName")
if filename = "" then
Response.Write "请输入filename参数,指定下载的文件名"
else
Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename =" & filename
Set FileStream = Server.CreateObject("Adodb.Stream")
FileStream.Mode = 3
FileStream.Type = 1
FileStream.Open
FileStream.LoadFromFile( Server.MapPath(filename))

Response.BinaryWrite( FileStream.Read )

FileStream.Close()
Set FileStream = nothing
end if
%>把上述代码存成asp类型的文件,使用时类似:download.asp?filename=a.gif。
2、使用WebClient
在下载按钮事件中加入如下代码
System.Net.WebClient wc = new System.Net.WebClient();
wc.DownloadFile( "http://localhost/a.gif", "c:\a.gif");
上述代码会把服务器端的a.gif文件在没有任何提示的情况下下载的客户端的c盘,没有任何提示还是比较可怕的,不过有的时候确实需要这样做。该代码也可以在桌面程序运行。

asp.net显示下载提示的下载网页程序
//打开要下载的文件
System.IO.FileStream r = new System.IO.FileStream(FileName, System.IO.FileMode.Open);
//设置基本信息
Response.Buffer = false;
Response.AddHeader("Connection", "Keep-Alive");
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + System.IO.Path.GetFileName(FileName));
Response.AddHeader("Content-Length", r.Length.ToString());

while (true)
{
//开辟缓冲区空间
byte[] buffer = new byte[1024];
//读取文件的数据
int leng = r.Read(buffer, 0, 1024);
if (leng == 0)//到文件尾,结束
break;
if (leng == 1024)//读出的文件数据长度等于缓冲区长度,直接将缓冲区数据写入
Response.BinaryWrite(buffer);
else
{
//读出文件数据比缓冲区小,重新定义缓冲区大小,只用于读取文件的最后一个数据块
byte[] b = new byte[leng];
for (int i = 0; i < leng; i++)
b[i] = buffer[i];
Response.BinaryWrite(b);
}
}
r.Close();//关闭下载文件
Response.End();//结束文件下载
该方法有下载提示框,服务器端可以知道何时下载完毕。


添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.