SaveToStream or SaveToFile corrupts file?

Technical support for Spire.Doc

Moderator: iceblue support

SaveToStream or SaveToFile corrupts file?

Postby InfoCon » Wed Jan 25, 2012 11:58 am

Dear team

I want to offer docx files for download via browser and I've a problem with SaveToStream/SaveToFile as it is corrupting a (my) docx file while saving.

My system:
- Spire.Doc Pro Edition for .NET (Hot Fix) Version:4.1.20 (Licensed version)
- .NET 4.0
- VS2010

I have a docx template (see attached) which opens fine in Word 2007 and 2010. When I run through my code below the browser forwards the file correctly to Word, but Word refuses to open because of a "unkown error, Position: /word/header1.xml, row: 1, column: 0". Trying to save the download instead of opening showed the same error. The stored file refuses to open with the same error.

I also tried to use SaveToFile and afterwards send the saved file to download, which causes the same error.

It appears that the save function does some modifications which corrrupt the file...? If you look at my code you see that I just open the file and save it to stream without any modifications.

Here my code. Hope you could give me a hint.

Code: Select all
        Dim tmplDocPath As String = "D:\Bericht.docx"

        Dim aStream As MemoryStream = New MemoryStream

        Dim doc As New Document()
        doc.LoadFromFile(tmplDocPath)
        doc.SaveToStream(aStream, FileFormat.Docx)

        Response.Clear()
        Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
        Response.AppendHeader("Content-Disposition:", "attachment; filename=Result.docx")
        Response.AppendHeader("Content-Length", aStream.Length.ToString())
        Response.BinaryWrite(aStream.ToArray())
        Response.Flush()
        Response.End()


Kind regards
Oliver
You do not have the required permissions to view the files attached to this post.
InfoCon
 
Posts: 9
Joined: Fri Aug 20, 2010 8:34 am

Re: SaveToStream or SaveToFile corrupts file?

Postby InfoCon » Wed Jan 25, 2012 1:32 pm

Additional information I found out.

If I setup a new docx and do NOT set page header and footer (leave empty), then the error does not appear. But although it opens, all textboxes and checkboxes of the original are replaced by "text only".

To conclude:
1) There shouldn't be any predefined page header or footer, otherwise the error pops up.
2) Existing textboxes and checkboxes in original file are lost and turned into simple text when saving.

As I need this functions (header/footer set before in template) and usage of form elements, a solution would be great.

Thanks
Oliver
InfoCon
 
Posts: 9
Joined: Fri Aug 20, 2010 8:34 am

Re: SaveToStream or SaveToFile corrupts file?

Postby Suvi.Wu » Thu Jan 26, 2012 8:59 am

Hello Oliver,
Thank you for your feedback and sorry for the inconvenience caused by us.

I am sorry for that Spire.Doc doesn't support the textbox and checkbox at this stage. We will inform you once we have any progress at this function.

Have a great day.
Thanks and regards.

Suvi
e-iceblue support
User avatar
Suvi.Wu
 
Posts: 156
Joined: Thu Oct 20, 2011 2:53 am


Return to Spire.Doc

Who is online

Users browsing this forum: No registered users and 0 guests