Free Support Forum -

Documents corrupt after upgrading dll and converting from .doc to .docx

I recently upgraded from a (quite old) version of Aspose Words to version Before that I had to work with .doc version of documents, but I convinced the client to upgrade so that we could work with .docx documents. Most of the documents we use are stored documents that are opened by the .Net code, data is inserted at bookmark locations and then the document is saved to the response so the user can decide what to do with it. When they go to open the documents straight from the browser, they get the “We’re sorry … the file cannot be opened because there are problems with the contents” error. If the document is saved and then opened it is fine. There is nothing especially complicated in the documents. The error happens even if it’s essentially a blank document with three bookmarks that have text inserted. I have changed the Save method to use this method:
Dim options As New OoxmlSaveOptions()
options.SaveFormat = SaveFormat.Docx
doc.Save(My.Response, “mydoc.docx”, ContentDisposition.Inline, options)

Are there methods in the basic build of the document that I need to change to make this work properly? The client is pretty annoyed with it and is asking me to go back to .doc versions which would be a shame. If it’s helpful I can upload both the blank document and the resulting completed one.
Can you help?


Please try to use this Document.Save Method (HttpResponse, String, ContentDisposition, SaveOptions) overload of Save method.

You can resolve the problem with DOCX by simply adding Response.End() after sending document to client browser. For some reasons, 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 you open your DOCX document in any binary editor. That is why Microsoft Word cannot open this document. If you add Response.End(), content of web page will not be added and document will be valid.

Also, if you are using GetBuffer method of MemoryStream anywhere in code, please try replacing it with ToArray method. Hope, this helps.

Thank you very much Awais. That solved the problem! So easy.