如何访问内存文件中的字节发送到Response? [英] How to access the bytes of in memory document to send to Response?

查看:97
本文介绍了如何访问内存文件中的字节发送到Response?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我没有得到它,我希望有人可以帮助我...

Ok, I don't get it and am hoping somebody can help me out here...

当访问者点击我网页上的链接时,  DocumentFormat.OpenXml.Wordprocessing.Document(变量:
caf_doc )已创建,然后应该是下载到访问者。

When a visitor clicks a link on my web page, a DocumentFormat.OpenXml.Wordprocessing.Document (variable: caf_doc) is created that then should be downloaded to the visitor.

我已经创建了下载所需的基本代码:

I've created the basic code needed for the download:

Document caf_doc = _oxd.CreateReportDocument(CafId);
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
Response.AppendHeader("Content-Disposition", String.Format("attachment; filename={0}", filename));

const int bufferLength = 10000;
byte [] buffer = new Byte [bufferLength];
int length = 0;
流下载= ???????????;执行{
if(Response.IsClientConnected)
{
length = download.Read(buffer,0,buffe rLength);
Response.OutputStream.Write(缓冲区,0,长度);
缓冲区=新字节[bufferLength];
}其他
{
length = -1;
}
}
while(length> 0);

const int bufferLength = 10000;
byte[] buffer = new Byte[bufferLength];
int length = 0;
Stream download = ?????????????;
do
{
if (Response.IsClientConnected)
{
length = download.Read(buffer, 0, bufferLength);
Response.OutputStream.Write(buffer, 0, length);
buffer = new Byte[bufferLength];
}
else
{
length = -1;
}
}
while (length > 0);

Response.Flush();
Response.End();

Response.Flush();
Response.End();

在的地方?????????我以前有一个FileStream,但由于实际文档不在文件系统上,而是在内存中,这不再适用。

In the place of ????????? I used to have a FileStream but since the actual document is NOT on the filesystem but rather it is in memory, this doesn't work anymore.

缺少什么是让这个工作?

What is the missing piece to get this working?

谢谢!

注意:我可能把它放在错误的论坛中但是当我尝试选择正确的类别时,没有列出的论坛因此无法保存!哎呀。 MS请让这些论坛更好!

NOTE: I probably put this in the wrong forum but when I try to select the correct category, there are no forums listed and therefore can't save! ARGH. MS please make these forums better!

推荐答案

嗨Eric,

Hi Eric,

任何ASP.Net应用程序问题的正确位置都是
的论坛之一 http: //forums.asp.net

The correct place for any ASP.Net application questions will be one of the forums at http://forums.asp.net

但是,在这种情况下,看起来Document对象有一个
获取流的Save()方法
。 所以你可以创建一个新的System.IO.MemoryStrem并保存到它,将它的位置重置为0,然后将它传递给你的代码。

In this case however, it looks like the Document object has a Save() method that takes a stream.  So you can just create a new System.IO.MemoryStrem and save to it, reset it's position to 0, and then pass it to your code.


这篇关于如何访问内存文件中的字节发送到Response?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆