开发者

ASP.NET Response.OutputStream problems

开发者 https://www.devze.com 2023-02-02 07:01 出处:网络
I\'m trying to send binary data to a client using Response.OutputStream but seem to be hav开发者_运维百科ing problems with it. My code is fairly simple and pretty much identical to working code I\'ve

I'm trying to send binary data to a client using Response.OutputStream but seem to be hav开发者_运维百科ing problems with it. My code is fairly simple and pretty much identical to working code I've used before, but nothing happens on the client when the code runs.

Response.Buffer = false;
Response.ContentType = @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.AppendHeader("content-length", genstream.Length.ToString());
Response.AppendHeader("content-disposition", string.Format("attachment; filename={0}.xlsx", filename));

byte[] buffer = new byte[1024];
genstream.Position = 0;

int n;
while ((n  = genstream.Read(buffer, 0, 1024) ) > 0)
{
    Response.OutputStream.Write(buffer, 0, n);
}

If there code there is fine, which it seems to be, what else could be causing this behaviour?


Use the Response BinaryWrite function and the Flush command. E.g:

Response.ContentType = @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.BinaryWrite(buffer);
Response.Flush();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号