如何不将文本保存到服务器,直接下载?? 如何在服务器生成文本流直接将文本不保存到硬盘直接下载给用户?就想用户直接点下载一样``该怎么样实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 Response.AppendHeader("Content-Disposition", "attachment;filename=文件名.txt"); Response.AppendHeader("Content-Disposition", "attachment;filename=文件名.txt");response.binarraywrite(xxx); 文件名.txt 这个还是要保存在服务器上面呀 生成文件流会吗?有了文件流就可以这样输出了,下面是一个输入pdf文件的例子private void ViewPdf(Stream fs) { Response.Clear(); Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode("采购订单.pdf")); Response.ContentType = "application/pdf"; long fileLength = fs.Length; int size = 10240;//10K一下载 byte[] readData = new byte[size]; if (size > fileLength) size = Convert.ToInt32(fileLength); long fPos = 0; bool isEnd = false; while (!isEnd) { if ((fPos + size) >= fileLength) { size = Convert.ToInt32(fileLength - fPos); isEnd = true; } readData = new byte[size]; fs.Position = fPos;//注意设置读取的位置 fs.Read(readData, 0, size); Response.BinaryWrite(readData); Response.OutputStream.Flush(); fPos += size; } fs.Close(); Response.OutputStream.Close(); Response.End();//非常重要,没有这句系统会把页面的HTML代码一起输出的。 Response.Close(); } 在HttpWebRequest中设置Proxy代理访问URL 与 设置IE代理之后访问URL 有何不同? 谁有.net 版b2b开源的代码? ASP.NET 100 分!! 用 window.open 方法打开一个子页,这子页如何能把父页面的值取过来? asp.net生成静态页面有谁吗?可以告诉我一下吗?把整个过程和原理讲一下. vs.net2005为什么不让我控件ID???? IIS问题 数据库字段名称用中文会不会影响数据在网页中的显示? 这两段代码的意思是什么,有什么区别? 执行出错:分析连接值对时需要“=”分隔符。 200分求51job中个人更新求职选项、地区功能 XML提问基础
response.binarraywrite(xxx);
有了文件流就可以这样输出了,下面是一个输入pdf文件的例子private void ViewPdf(Stream fs)
{
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment;FileName=" + HttpUtility.UrlEncode("采购订单.pdf"));
Response.ContentType = "application/pdf";
long fileLength = fs.Length;
int size = 10240;//10K一下载
byte[] readData = new byte[size];
if (size > fileLength)
size = Convert.ToInt32(fileLength);
long fPos = 0;
bool isEnd = false;
while (!isEnd)
{
if ((fPos + size) >= fileLength)
{
size = Convert.ToInt32(fileLength - fPos);
isEnd = true;
}
readData = new byte[size];
fs.Position = fPos;//注意设置读取的位置
fs.Read(readData, 0, size);
Response.BinaryWrite(readData);
Response.OutputStream.Flush();
fPos += size;
}
fs.Close();
Response.OutputStream.Close();
Response.End();//非常重要,没有这句系统会把页面的HTML代码一起输出的。
Response.Close();
}