We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Getting a corrupt DOCX when saving to ASP.NET HTTP response

I have downloaded the most recent version of Aspose.Words (13.1) and received a evaluation license from the sales department.
I have been evaluating Aspose.Words for use with an ASP.NET web site.
But I an having a problem when saving a document as a .docx file using the HTTP Response version of the Document.Save() method.

To reproduce, I created a brand new Word document using Word 2010 and type in one sentence then saved as a .docx file.
I created a brand new ASP.Net website project using Visual Studio 2010.
I added the Aspose.Words DLL file and my evaluation license file to the website’s bin folder.
I added a reference to the DLL to my website project.
In the Application_Start method I applied my license file.
I used the default.aspx page that is included in the new website project and wrote some sample code that reproduces the error.
The error only seems to occur when using the HTTP Response version of the Save() method to save the document as a .docx file type.
The other Save() versions and other document types work correctly.

Attached to this post is a zip file containing the website project and the .docx file I used.
Also in the zip file are the results of the different .docx. files that were saved with Aspose.Words using the different save methods and screen shots of Word 2010 when attempting to open the problem documents.
When I say Yes for Word to recover the document it does open correctly at that point.

I am not sure if this is an bug with Aspose.Words or a result of me using a evaluation license.
Please let me know if there is anything else I can provide to help figure out what the problem might be.

Thank you Dave P.

Hi David,

Thanks for your inquiry. To resolve the problem with DOCX you should simply add Response.End() after sending document to client browser. This will resolve the problem. When you save a DOCX document to client browser, content of web page is added at the end of the document, you can see this if open your DOCX document in any binary editor. That is why MS Word cannot open this document. If you add Response.End(), content of web page will not be added and document will be valid.

Dim doc As New Aspose.Words.Document(“C:\NewDocument.docx”)<o:p></o:p>

doc.Save(Response, “NewDocumentAttachment.docx”, Aspose.Words.ContentDisposition.Attachment, Nothing)<o:p></o:p>


Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.

Thank you for your response.
I added a call to End() and it worked.
I’m a little embarrassed, I should have realized I had to call End().
The documentation for this version of the Save() method does not mention that you still need to call End().
I just assumed that the Save() method was doing that.

Hi David,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. We will add information about Response.End() in documentation soon. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.