【问题标题】:Streaming PowerPoint file in ASP.NET在 ASP.NET 中流式传输 PowerPoint 文件
【发布时间】:2014-10-14 15:15:43
【问题描述】:

我正在生成 PowerPoint 幻灯片,然后即时合并它们,然后通过 HttpResponse 对象流式传输生成的内容,即

            HttpResponse response = HttpContext.Current.Response;
            response.Clear();
            response.AppendHeader("Content-Type", "application/vnd.ms-powerpoint");
            response.AppendHeader("Content-Disposition", "attachment;filename=MasterPresentation.pptx;");
            response.BinaryWrite(masterPresentation.ToArray());
            response.Flush();
            response.Close();

ma​​sterPresentation 是一个 MemoryStream 对象。当我在 PowerPoint 中打开下载的演示文稿时,我收到以下消息:

PowerPoint 发现 MasterPresentation.pptx 中的内容存在问题。 PowerPoint 可以尝试修复演示文稿。

修复后一切似乎都很好,没有任何内容损坏。

【问题讨论】:

  • 您是否尝试过检查生成文件和“修复”文件之间的差异?
  • @PhonicUK 是的,我尝试比较 OpenXML SDK 生产力工具中的文件,但无法打开损坏的文件。我应该使用哪个其他工具来比较这些文件?
  • 某种十六进制编辑器。

标签: c# asp.net .net httpresponse


【解决方案1】:

我正在回答我自己的问题,如果其他人需要解决此问题,您只需更换:

        response.Flush();
        response.Close();

        response.End();

捕获任何异常并且生成的演示文稿不会被破坏。

【讨论】:

  • 是的。 “%officeProgram% 发现 %ooxmlFile% 中的内容有问题。%officeProgram 可以尝试修复演示文稿。”当包含的 zip 文件未正确终止时,通常会出现错误消息,即使其中包含的 XML 文件非常好。
猜你喜欢
  • 1970-01-01
  • 2012-12-08
  • 2010-10-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-20
  • 2017-07-07
相关资源
最近更新 更多