Aspose.Words 直接写response导出docx文档显示文件已损坏需要修复的解决办法

时间:2022-09-03 10:19:19

使用Aspose.Words的Document.Save(HttpResponse response, string fileName, ContentDisposition contentDisposition, Aspose.Words.Saving.SaveOption saveOption)方法,将Document直接写入response时,需要加Response.End();

Document doc = new Document(postedFile.InputStream);
doc.Save(Response, dstFileName, ContentDisposition.Inline, SaveOptions.CreateSaveOptions(dstFormat));
// Required. Otherwise DOCX cannot be opened on the client (probably not all data sent
// or some extra data sent in the response).
Response.End();

请注意注释部分!!