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

Reading number is top 10 articles
在.Net,里用XPath的case-insensitive,的查询_.net资料_编程技术
在asp.net中做视频转换,将各种视频文件转换成.flv格式_[Asp.Net教程]
Visual,C#命名空间详解_[Asp.Net教程]
PHP实例:PHP批量生成缩略图_[PHP教程]
c#中GDI+图形图像:GDI+中的区域使用方法
SQL注入天书之ASP注入漏洞全接触_[SQL,Server教程]
浅谈当下网页设计趋势_优化技巧_seo学堂
PHP实例:PHP安全编程之加密功能_[PHP教程]
Sql,server,2005加强的十大安全举措_[SQL,Server教程]
DataTable操作中的性能问题_[Asp.Net教程]
Reading number is top 10 pictures
去瑜伽会所面试的经过
Photographed the passion of the clients and prostitutes in the sex trade picture2
囚犯暴乱了咋办?
The money of more than 100 countries and regions19
俞敏洪在清华终于说了实话
The goddess of the single reason2
人美胸美腿更美4
西游四格漫画(一)
好身材能把衣服穿出3D效果
BingBingFan apple dew point photo gallery1
Download software ranking
Sora aoi‘s film--Lust fan wall
打鸟视频
Unix video tutorial6
jdk1.5
Boxer's Top ten classic battle6
Unix video tutorial20
Macromedia Dreamweaver 8
Unix video tutorial17
WebService在.NET中的实战应用教学视频 → 第4集
Such love down(擒爱记)
aaa published in(发表于) 2013/12/8 7:50:46 Edit(编辑)
ASP.NET技巧:下载文件关闭窗体之解决方法_.net资料_编程技术

ASP.NET技巧:下载文件关闭窗体之解决方法_.net资料_编程技术

ASP.NET技巧:下载文件关闭窗体之解决方法_.net资料_编程技术-你的首页-uuhomepage.com

对于下载时新打开一窗口下载,下载完后需要关闭的
一种:对于较小文件可以有效:
System.IO.FileInfo file = new System.IO.FileInfo("F:\\mp3\\mp3\\别哭我最爱的人.mp3");
Response.Clear();
Response.ClearHeaders();
Response.Buffer = false;
Response.Charset="GB2312";
Response.ContentEncoding=System.Text.Encoding.UTF8;
Response.ContentType = "application/octet-stream";

Response.AddHeader("Content-Disposition", "attachment; filename="+Server.UrlEncode("别哭我最爱的人.mp3"));
Response.AddHeader("Content-Length", file.Length.ToString());



Response.WriteFile(file.FullName);
Response.Flush();
Response.End();
该代码可以实现输出文件并将新打开的窗体关闭。


另一种对于大文件,我们用上述代码不是较好,因为上述代码是将文件全缓存于服务器后才输出的,如果你的服务器流量大,且文件较大,不建议用以上方法。


以下我测试过,较好能解决:
public static bool ResponseFile(HttpRequest _Request,HttpResponse _Response,string _fileName,string _fullPath, long _speed)
{
try
{
FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
BinaryReader br = new BinaryReader(myFile);
try
{
_Response.AddHeader("Accept-Ranges", "bytes");
_Response.Buffer = false;
long fileLength = myFile.Length;
long startBytes = 0;

int pack = 10240; //10K bytes
int sleep = (int)Math.Floor(1000 * pack / _speed) + 1;
if (_Request.Headers["Range"] != null)
{
_Response.StatusCode = 206;
string[] range = _Request.Headers["Range"].Split(new char[] {'=', '-'});
startBytes = Convert.ToInt64(range[1]);
}
_Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
if (startBytes != 0)
{
_Response.AddHeader("Content-Range", string.Format(" bytes {0}-{1}/{2}", startBytes, fileLength-1, fileLength));
}
_Response.AddHeader("Connection", "Keep-Alive");
_Response.ContentType = "application/octet-stream";
_Response.AddHeader("Content-Disposition","attachment;filename=" + HttpUtility.UrlEncode(_fileName,System.Text.Encoding.UTF8) );

br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
int maxCount = (int) Math.Floor((fileLength - startBytes) / pack) + 1;


for (int i = 0; i < maxCount; i++)
{
if (_Response.IsClientConnected)
{
_Response.BinaryWrite(br.ReadBytes(pack));
Thread.Sleep(sleep);
}
else
{
i=maxCount;
}
}
_Response.Flush();
}
catch
{
return false;
}
finally
{
br.Close();
myFile.Close();
}
}
catch
{
return false;
}
return true;
}
这一种代码也是借签网上的
它也可以实现输出文件并关闭新打开幕窗体


另外在测试当中发现,服务器端与客户的操作系统不同
也会有一些意想不到的事情发生
一般来说,用以上代码,如不能正常关闭,你可以查阅浏览器的设置,在高级中。
再者,你可以修改不同的输出内容类型Response.ContentType = "application/octet-stream";因为不同的contenttype,在客户的端的解释可能是不一样的。
有想法请回复,欢迎讨论






添加到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.