写的MemoryStream到响应对象 [英] Writing MemoryStream to Response Object

查看:282
本文介绍了写的MemoryStream到响应对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用下面的code流PPTX这是MemoryStream对象,但是当我打开它,我得到在PowerPoint中修复的消息,什么是写的MemoryStream到响应对象?

的正确方法

 的Htt presponse响应= HttpContext.Current.Response;
response.Clear();
response.AppendHeader(内容类型,应用程序/ vnd.openxmlformats-officedocument presentationml presentation。);
response.AppendHeader(内容处置的String.Format(附件;文件名= {0} .PPTX;,getLegalFileName(当前presentation presentation_NM)));
response.BinaryWrite(主presentation.ToArray());
到Response.End();


解决方案

我有同样的问题,只是工作的解决方案是:

  Response.Clear();
Response.ContentType =应用程序/ msword
Response.AddHeader(内容处置,附件;文件名= myfile.docx);
Response.BinaryWrite(myMemoryStream.ToArray());
// myMemoryStream.WriteTo(Response.OutputStream); //工程太
Response.Flush();
Response.Close();
到Response.End();

I am using the following code to stream pptx which is in a MemoryStream object but when I open it I get Repair message in PowerPoint, what is the correct way of writing MemoryStream to Response Object?

HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.AppendHeader("Content-Type", "application/vnd.openxmlformats-officedocument.presentationml.presentation");
response.AppendHeader("Content-Disposition", string.Format("attachment;filename={0}.pptx;", getLegalFileName(CurrentPresentation.Presentation_NM)));                
response.BinaryWrite(masterPresentation.ToArray());
response.End();

解决方案

I had the same problem and the only solution that worked was:

Response.Clear();
Response.ContentType = "Application/msword";
Response.AddHeader("Content-Disposition", "attachment; filename=myfile.docx");
Response.BinaryWrite(myMemoryStream.ToArray());
// myMemoryStream.WriteTo(Response.OutputStream); //works too
Response.Flush();
Response.Close();
Response.End();

这篇关于写的MemoryStream到响应对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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