【Jinglecat(晓风残月 >> 问题需简洁,错误要详细) ——————为什么pdf文件下载会出现问题?】 浏览器如果有pdf插件就会直接在浏览器打开pdf文件,而不会出现下载对话框半年后我也要成为这里的高手,等着瞧吧 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不好,这一问把偶问蒙了 ....1。下载代码片段在哪里啊?用的什么下载代码?二进制流下载?用 window.open 打开?关于空白页问题,我碰到过,但是尝试其他客户端,又没有这种现象,我也不知道具体原因也许是,由于你指定的文件格式,在客户端上没有对应可打开的应用程序2。假如你装了 pdf 阅读器,会自动打开的 起个脚本.在输出内容前.先发送 传送附件送.即可...response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename,"UTF8")); 下面这段下载代码片段,在我机器上,测试了多种文件类型,是不会出现你的问题:protected void Page_Init(object sender, EventArgs e) { string downFilePath = Server.MapPath("01.初识 ASP.NET.pps"); System.IO.FileInfo downFileInfo = new System.IO.FileInfo(downFilePath); if (!downFileInfo.Exists) throw new Exception("文件不存在。"); const int CHUNK_SIZE = 10000; // 指定块大小 byte[] buffer = new byte[CHUNK_SIZE]; Response.Clear(); // fails to down the big file with both the following methods // error: System.ArgumentOutOfRangeException: 大小参数必须介于零和最大的 Int32 值之间。 // Response.WriteFile(downFilePath); // OR // Response.TransmitFile(downFilePath); // ASP.NET 2.0 supported // using (System.IO.FileStream iStream = System.IO.File.OpenRead(downFilePath)) { long dataLengthToRead = iStream.Length; Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlPathEncode(downFileInfo.Name)); // 对文件名进行编码 while (dataLengthToRead > 0 && Response.IsClientConnected) { int lengthRead = iStream.Read(buffer, 0, CHUNK_SIZE); Response.OutputStream.Write(buffer, 0, lengthRead); Response.Flush(); dataLengthToRead = dataLengthToRead - lengthRead; } } Response.Close(); } 请问如何弹出一个带图片和按钮的小窗体,谢谢 求一个ext tree加载数据库数据 形成树的代码, 未能在“设计”视图中打开。用引号将“<% %>”块括起来,该块用作属性值或用在 <SELECT> 元素中 弹窗之后,字体全乱 水晶报表列显示不全的问题 使用Data Access Application Block里面遇到的一个的问题 各位大侠帮个忙,非常急,在线等,解决了利马给分 我是新手!我想学习ASP.NET技术,求助! 在web中怎么调用如.exe之类的应用程序 谁能介绍一下session的用法??怎样在不同页面之间传递session??谢谢!! 出错,帮忙 如何判断是空值
下载代码片段在哪里啊?用的什么下载代码?二进制流下载?用 window.open 打开?关于空白页问题,我碰到过,但是尝试其他客户端,又没有这种现象,我也不知道具体原因也许是,由于你指定的文件格式,在客户端上没有对应可打开的应用程序
2。
假如你装了 pdf 阅读器,会自动打开的
response.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename,"UTF8"));
{
string downFilePath = Server.MapPath("01.初识 ASP.NET.pps");
System.IO.FileInfo downFileInfo = new System.IO.FileInfo(downFilePath); if (!downFileInfo.Exists) throw new Exception("文件不存在。");
const int CHUNK_SIZE = 10000; // 指定块大小
byte[] buffer = new byte[CHUNK_SIZE]; Response.Clear();
// fails to down the big file with both the following methods
// error: System.ArgumentOutOfRangeException: 大小参数必须介于零和最大的 Int32 值之间。
// Response.WriteFile(downFilePath);
// OR
// Response.TransmitFile(downFilePath); // ASP.NET 2.0 supported
//
using (System.IO.FileStream iStream = System.IO.File.OpenRead(downFilePath)) {
long dataLengthToRead = iStream.Length;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition",
"attachment; filename=" + Server.UrlPathEncode(downFileInfo.Name)); // 对文件名进行编码
while (dataLengthToRead > 0 && Response.IsClientConnected) {
int lengthRead = iStream.Read(buffer, 0, CHUNK_SIZE);
Response.OutputStream.Write(buffer, 0, lengthRead);
Response.Flush();
dataLengthToRead = dataLengthToRead - lengthRead;
}
}
Response.Close();
}