我实现的下载功能是这样写的
string filepath="";
filepath=Server.MapPath("ImgeTemp")+"\\temp.jpg";
System.IO.FileInfo myFile = new System.IO.FileInfo(filepath);
filename=this.Request["ImgePath"];
filename=filename.Substring(filename.Length-3,3);
if (filename=="jpg")
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(myFile.Name));
}
else
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("temp.tif"));
}
Response.AddHeader("Content-Length", myFile.Length.ToString());
this.Response.ContentType="application/octet-stream";
Response.WriteFile(myFile.FullName);
this.Response.End();
能实现下载~但下载完后下载页面一直留在那里~无法自动关闭~我试着在最后加了window.close()但还是不行~而且加了之后流有问题~希望高手指点一下
string filepath="";
filepath=Server.MapPath("ImgeTemp")+"\\temp.jpg";
System.IO.FileInfo myFile = new System.IO.FileInfo(filepath);
filename=this.Request["ImgePath"];
filename=filename.Substring(filename.Length-3,3);
if (filename=="jpg")
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(myFile.Name));
}
else
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("temp.tif"));
}
Response.AddHeader("Content-Length", myFile.Length.ToString());
this.Response.ContentType="application/octet-stream";
Response.WriteFile(myFile.FullName);
this.Response.End();
能实现下载~但下载完后下载页面一直留在那里~无法自动关闭~我试着在最后加了window.close()但还是不行~而且加了之后流有问题~希望高手指点一下
解决方案 »
- 怎样在asp.net里面加flash视频并控制是否播放
- asp.net网站开发
- 有点菜的问题
- 大家有空去见识下 牛B 的 aspx , 我是长呢不少见识...
- 现在只有一个SqlDataSource,不知道咋用了。
- 继承自Repeater的控件怎样在代码添加HeaderTemplate和FooterTemplate?
- 一个诡异的问题-----关于打包时的image文件夹
- 帮看一下对吗
- 请问如何从ASP.NET 页中通过按钮调用别的页面,常用的有什么方法!
- 将datagrid中的数据保存到excel的问题,我没分了
- 新作的一个网络收藏夹网站
- 论坛发贴生成静态页,那回复贴的时候生成静态页是什么原理
string filepath="";
filepath=Server.MapPath("ImgeTemp")+"\\temp.jpg";
System.IO.FileInfo myFile = new System.IO.FileInfo(filepath);
filename=this.Request["ImgePath"];
filename=filename.Substring(filename.Length-3,3);
if (filename=="jpg")
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(myFile.Name));
}
else
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("temp.tif"));
}
Response.AddHeader("Content-Length", myFile.Length.ToString());
this.Response.ContentType="application/octet-stream";
Response.WriteFile(myFile.FullName);
Response.flush();
this.Response.End();
如果是window.open()的话,你可以试着window.close();
或window.openner=null;window.close();
我的源代码给你
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();
这个方法我试过的不行啊~~555
放在
Response.End();
之前
string filepath="";
filepath=Server.MapPath("ImgeTemp")+"\\temp.jpg";
System.IO.FileInfo myFile = new System.IO.FileInfo(filepath);
filename=this.Request["ImgePath"];
filename=filename.Substring(filename.Length-3,3);
if (filename=="jpg")
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(myFile.Name));
}
else
{
Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode("temp.tif"));
}
Response.AddHeader("Content-Length", myFile.Length.ToString());
this.Response.ContentType="application/octet-stream";
Response.WriteFile(myFile.FullName);
Response.Write("<script language=javascript>window.openner=null;window.close();</script>");
this.Response.End();
这样的方法肯定是不行的,不管你在什么时候写
但不要加target="_blank"
在本页跳转
我相信上述我写的代码应该可以
<head>
<title>CSDN技术网摘 -- wz.csdn.net</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link rel="StyleSheet" href="/main.css" type="text/css" media="screen"><script type="text/javascript">
function closeIt() {
self.close();
}
function doClose() {
setTimeout("closeIt()", 2000);
}
</script>
</head><body bgcolor="white" onLoad="doClose();">
<table width="100%" height="75%" border="0" cellspacing="0" cellpadding="0">
<tr><td valign="center">
<center><table width="300" class="greenBox">
<tr><th>成功啦!</th></tr>
<tr><td align="center">
<span class="success">网页成功保存.</span><br/><br/>
<a href="/my" target="_blank">进入我的网摘管理</a>
</td></tr>
</table></center>
</td></tr>
</table>
</body>
</html>