gpt4 book ai didi

c# - 将 MemoryStream 写入响应对象

转载 作者:IT王子 更新时间:2023-10-29 04:01:53 28 4
gpt4 key购买 nike

我正在使用以下代码来流式传输 MemoryStream 对象中的 pptx,但是当我打开它时,我在 PowerPoint 中收到修复消息,将 MemoryStream 写入响应对象的正确方法是什么?

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();

最佳答案

我遇到了同样的问题,唯一有效的解决方案是:

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();

关于c# - 将 MemoryStream 写入响应对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13779139/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com