C# 如何将字节流写入缓冲区
代码如下,我从数据库中拿到了存入的word,那么现在如何将这个byte[]类型的wordFile存入缓冲区,发送到客户端呢?stringid=Request.QueryS...
代码如下,我从数据库中拿到了存入的word,那么现在如何将这个byte[]类型的wordFile存入缓冲区,发送到客户端呢?
string id = Request.QueryString["id"];
WordInfo wi = new WordInfo();//声明实体类
wi=BLL.WordInfoManager.GetWordInfoByWordId(int.Parse(id));//从数据库获得数据
byte[] wordFile = wi.Wordfile;//把二进制word数据存入byte[]
byte[] buffer = new Byte[10240];//声明一个字节数组
BufferedStream bs = new BufferedStream(wordFile);
int curPos = 0;
int readsize = 0;
long size = bs.Length;
readsize=bs.Read(buffer, 0, 10240);
while (readsize == 10240)
{
curPos += readsize;
Response.BinaryWrite(buffer);
Response.Flush();
readsize = bs.Read(buffer, curPos, 10240);
}
byte[] bfEnd = new byte[readsize];
bs.Read(bfEnd, curPos, readsize);
Response.BinaryWrite(bfEnd);
Response.Flush();
我这样写错了,我的意思是,输出word二进制流到客户端,怎么弄呢. 展开
string id = Request.QueryString["id"];
WordInfo wi = new WordInfo();//声明实体类
wi=BLL.WordInfoManager.GetWordInfoByWordId(int.Parse(id));//从数据库获得数据
byte[] wordFile = wi.Wordfile;//把二进制word数据存入byte[]
byte[] buffer = new Byte[10240];//声明一个字节数组
BufferedStream bs = new BufferedStream(wordFile);
int curPos = 0;
int readsize = 0;
long size = bs.Length;
readsize=bs.Read(buffer, 0, 10240);
while (readsize == 10240)
{
curPos += readsize;
Response.BinaryWrite(buffer);
Response.Flush();
readsize = bs.Read(buffer, curPos, 10240);
}
byte[] bfEnd = new byte[readsize];
bs.Read(bfEnd, curPos, readsize);
Response.BinaryWrite(bfEnd);
Response.Flush();
我这样写错了,我的意思是,输出word二进制流到客户端,怎么弄呢. 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询