在ASP.NET中,通过主程序调用一个Download子页面,如以下代码所示,在XP系统中是正常的。
但是在Windows Server 2003系统中,在Download页面中选择保存、正常保存后,
在任务管理器的应用程序中会保留刚才的Download任务。 Download页面,像用IE下载文件相同的对话框,有打开,保存,取消三个按钮,
打开和取消都没有问题,只有保存,任务才会残留在任务列表中。 求助:如何才能保存结束后关掉那个Download任务。
是否需要进行什么特殊处理,或者是XP系统和2003的什么区别? severPath = Session("SeverPath")
downLoadFile = New System.IO.FileInfo(filePath)
bufOutPut = Page.Response.BufferOutput.ToString
Page.Response.Clear() Page.Response.AddHeader("Content-Disposition", "attachment;filename=" & _
System.Web.HttpUtility.UrlEncode(downLoadFile.Name))
Page.Response.AddHeader("Content-Length", downLoadFile.Length.ToString()) Page.Response.ContentType = "application/vnd.ms-excel"
Try
Page.Response.WriteFile(downLoadFile.FullName)
Catch ex As Exception
......
End Try Page.Response.Write(bufOutPut)
Page.Response.End()
但是在Windows Server 2003系统中,在Download页面中选择保存、正常保存后,
在任务管理器的应用程序中会保留刚才的Download任务。 Download页面,像用IE下载文件相同的对话框,有打开,保存,取消三个按钮,
打开和取消都没有问题,只有保存,任务才会残留在任务列表中。 求助:如何才能保存结束后关掉那个Download任务。
是否需要进行什么特殊处理,或者是XP系统和2003的什么区别? severPath = Session("SeverPath")
downLoadFile = New System.IO.FileInfo(filePath)
bufOutPut = Page.Response.BufferOutput.ToString
Page.Response.Clear() Page.Response.AddHeader("Content-Disposition", "attachment;filename=" & _
System.Web.HttpUtility.UrlEncode(downLoadFile.Name))
Page.Response.AddHeader("Content-Length", downLoadFile.Length.ToString()) Page.Response.ContentType = "application/vnd.ms-excel"
Try
Page.Response.WriteFile(downLoadFile.FullName)
Catch ex As Exception
......
End Try Page.Response.Write(bufOutPut)
Page.Response.End()
解决方案 »
- 求助一个分类信息网站数据库优化和网站建设的问题。
- 求高人指点一下,这个错误百度都没有
- .net 怎么用ajax读取sql server数据库里的数据,然后再传回前台页面显示
- 如何实现在线考试系统中的禁止切屏功能
- gridview用储存过程分页后gridview样式怎么做?
- Forms身份验证中遇到的问题与思考?
- 在.net中可不可以操作xsl.
- %u4E00%u4E2A%u4EBA
- 发现一个问题,如果按钮的CauseValidition设置为true会导致showModalDialog失效
- ado.net批量更新超时问题
- fckeditor图片路径
- 有关C#中Serializable序列化的问题
然后到不同的机器上远程访问,在Server2000 或者Server 2003 上出现关不掉空白页面的问题。在XP上调用,不会出现这个问题。
Response.ContentType = "application/force-download";
Response.AddHeader("Content-Disposition", "attachment;filename="+fileName);
Response.WriteFile(fullName);
this.ClientScript.RegisterStartupScript(this.GetType(), "", "<script>window.close();</script>");
问题依旧。谢谢楼上的。。
但是Download成功之后,页面就没有相应了。还是不行的。。
/// <summary>
/// 下载文件
/// </summary>
/// <param name="FilePath">文件路径</param>
/// <param name="FileName">文件别名</param>
public static void Download(string FilePath, string FileName)
{
if (string.IsNullOrEmpty(FilePath))
{
return;
} if (FilePath.StartsWith("~"))
{
FilePath = HttpContext.Current.Server.MapPath(FilePath);
}
if (!File.Exists(FilePath))
{
// 文件不存在
HttpContext.Current.Response.Write("文件不存在");
return;
}
if (string.IsNullOrEmpty(FileName))
{
FileName = System.IO.Path.GetFileName(FilePath);//原始文件名
}
else
{
string Extension = System.IO.Path.GetExtension(FilePath);
if (!FileName.EndsWith(Extension))
FileName += Extension;
}
HttpContext.Current.Response.Clear();
HttpContext.Current.Response.ContentType = "application/octet-stream";
// 文件名格式化
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment; FileName=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8));
HttpContext.Current.Response.TransmitFile(FilePath);
HttpContext.Current.Response.End();
}
public static void Download(string FilePath)
{
Download(FilePath, string.Empty);
}
#endregion
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();
这个我也试过了。但是Download一次之后,主页面就不会有别的事件相应了。所以还是不行的啊。。