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

Free Support Forum - aspose.com

ASPOSE.WORDS unreadable content when opening

Hi, i have a trial licence at the moment and am just creating a simple bit of code to make sure the DLLs are working, however with the following sample code;

Sub test(ByRef context As HttpContext, strCode As String)
        Dim sDocPath As String = context.Server.MapPath(".") & "\templates\word"
        Dim docStream As New System.IO.FileStream(IO.Path.Combine(sDocPath, "RD Record Sheet.docx"), IO.FileMode.Open, IO.FileAccess.Read, IO.FileShare.ReadWrite)
        Dim doc As New Document(docStream)

        doc.Range.Replace("{{ADDRESS}}", "Somewhere in the world")

        Dim options As OoxmlSaveOptions = New OoxmlSaveOptions()
        options.SaveFormat = SaveFormat.Docx

        doc.Save(context.Response, "Record - " & strCode & ".docx", ContentDisposition.Attachment, options)
    End Sub

When i create the document i get the following message from MS Word;
"Word found unreadable content in XXXXXX.docx do you want to recover the contents etc

What am I doing wrong here ?

Clearly the original DOCX file that i use to open at the beginning of the code is a valid DOCX file, so why can I not export it back to the browser and be able to open it ?

Kind regards

Matt

@matthewsimpson Could you please attach your input and output documents here for testing? We will check the issue and provide you more information.

Thanks for response, I Cannot attach input or output documents for confidentiality reasons.

To say that the original document can be opened in word no problem, but it is only when i convert it using ASPWORDS it seems to get “corrupt”.

I have also tried a simple document (test.docx) and the same issue arises. This document i can attach test.docx (11.8 KB)

The output file i get is looking ok, but I get the same Word Error when opening from Web Browser.

As in when the file comes down to the browser I still get

Word found unreadable content in XXXXXX.docx do you want to recover the contents etc

I just need a simple example in C# or VB to open a document, do something to it, like find, replace, then output that document to a browser that will open in Word

Thanks

Matt

@matthewsimpson Thank you for additional information. I think, to resolve the problem with DOCX you should simply add Response.End() after sending document to client browser. This will resolve the problem.

For some reason 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.

Magic, that worked a treat with the simple response.end() after the .SAVE method.

Thanks for your help

@matthewsimpson It is perfect that the problem is resolved. Please feel free to ask in case of any issues. We are always here to help you.