I was not sure under which topic to post this. So posting it here.
I have built a basic website for a company where I build a word document(.docx) file dynamically by using a template word doc and content controls and Open XML SDK. Its an ASP.NET MVC 2 based website. I used the same code shown in this link where they build
a Sales Contract document using Open XML. You can find it at almost the last section of the page seen in the following link:
My problem is everything works fine on my development system. But when I host the application on GoDaddy servers and at the end when the Word Document is saved, Microsoft Word says the document is corrupt and has to be recovered.
I tried the same and it did not work for me and I get the same error and now I am clueless as to where the error actually is.
Any help would be greatly appreciated.
P.S: I had posted this in the Open XML SDK forums and I got a reply that its not a problem from the Open XML SDK as the word doc is being built perfectly fine.
There is must be no difference in what enviroment you are running you application. If MS Word says that the document your app has created is corupt, than it probably is. The message you are seeing can mean anything (invalid resource ID format, missing table
row index, missing image part, ...) and it is impossible to say what you are doing wrong.
What you can do: Open your corrupt document as a ZIP package and open the document.xml part. Try to cut-out it content piece by piece and every time save it back to the package. Do it for so long until the until the document will become non-corrupt. This
way you can discover which part of the document is corrupt and will be maybe able to relate it to a pice of code in your program.
It's good to have OpenXml SDK around, but programming against it is quite tedious, especially due to problems you encountered. I recommend you to find yourself a 3rd party solution like
Docentric. It offers you template-based approch with designing templates in MS word.
-- Jure
asp.net-mvc
Marked as answer by Qi Wu - MSFT on Dec 01, 2011 12:25 PM
I did try what you said. I infact passed a blank document but even then it gives me the same error. Do you think its something to do with the TransmitFile() function??
If you suspect that the file gets corrupted while transfered to the client-side, then you can temporarily add the code that saves the generated document to a local disk on the server. Then you can compare both files the one that you recieved as a client
and the one that was saved on the server. Of course, for the experiment you will the access to the production server and also permision to do that.
Or you can also do the following: If you can achieve exactly the same contitions and input parameters into document generation process on the development and the production server where you can assert that the generated documents must be exactly the same,
you can make a comparison between these two.
I'm encountering the same issue. What is the proper setting for the MIME type? By the way, are you generating a .dotx file or a .docx file? It .docx, how did you do it?
hello, how did you managed to make the code on the msdn page work. I tryed but with no effect on the document (dotx) created. It still haves the placeholders, no text from the XML. thanks..
All I did was to follow the steps given in that link. No modifications to that. You may be missing something. May not be linking the fields properly. Just check the XML being generated once and check if the name of the tags in the XML match the name of the
placeholders in your template.
mvcNewbie
Member
6 Points
5 Posts
Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened from ...
Nov 24, 2011 11:17 PM|LINK
I was not sure under which topic to post this. So posting it here.
I have built a basic website for a company where I build a word document(.docx) file dynamically by using a template word doc and content controls and Open XML SDK. Its an ASP.NET MVC 2 based website. I used the same code shown in this link where they build a Sales Contract document using Open XML. You can find it at almost the last section of the page seen in the following link:
http://msdn.microsoft.com/en-us/library/dd469465(v=office.12).aspx
My problem is everything works fine on my development system. But when I host the application on GoDaddy servers and at the end when the Word Document is saved, Microsoft Word says the document is corrupt and has to be recovered.
I saw a similar question in the following link: http://stackoverflow.com/questions/2477564/why-are-docx-files-being-corrupted-when-downloading-from-an-asp-net-page
I tried the same and it did not work for me and I get the same error and now I am clueless as to where the error actually is.
Any help would be greatly appreciated.
P.S: I had posted this in the Open XML SDK forums and I got a reply that its not a problem from the Open XML SDK as the word doc is being built perfectly fine.
asp.net-mvc
Jure.Les
Member
376 Points
69 Posts
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
Nov 25, 2011 08:34 AM|LINK
Hi!
There is must be no difference in what enviroment you are running you application. If MS Word says that the document your app has created is corupt, than it probably is. The message you are seeing can mean anything (invalid resource ID format, missing table row index, missing image part, ...) and it is impossible to say what you are doing wrong.
What you can do: Open your corrupt document as a ZIP package and open the document.xml part. Try to cut-out it content piece by piece and every time save it back to the package. Do it for so long until the until the document will become non-corrupt. This way you can discover which part of the document is corrupt and will be maybe able to relate it to a pice of code in your program.
It's good to have OpenXml SDK around, but programming against it is quite tedious, especially due to problems you encountered. I recommend you to find yourself a 3rd party solution like Docentric. It offers you template-based approch with designing templates in MS word.
-- Jure
asp.net-mvc
mvcNewbie
Member
6 Points
5 Posts
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
Dec 20, 2011 03:04 AM|LINK
@Jure.Les
I did try what you said. I infact passed a blank document but even then it gives me the same error. Do you think its something to do with the TransmitFile() function??
asp.net-mvc
Jure.Les
Member
376 Points
69 Posts
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
Dec 20, 2011 07:13 AM|LINK
If you suspect that the file gets corrupted while transfered to the client-side, then you can temporarily add the code that saves the generated document to a local disk on the server. Then you can compare both files the one that you recieved as a client and the one that was saved on the server. Of course, for the experiment you will the access to the production server and also permision to do that.
Or you can also do the following: If you can achieve exactly the same contitions and input parameters into document generation process on the development and the production server where you can assert that the generated documents must be exactly the same, you can make a comparison between these two.
-- Jure
asp.net-mvc
mvcNewbie
Member
6 Points
5 Posts
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
Dec 21, 2011 12:56 PM|LINK
Atlast problem solved. The problem was in setting the MIME type. I set it properly and it works fine now. Thanks for all the help Jure!!
patrickgeige...
Member
2 Points
1 Post
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
Mar 23, 2012 01:50 AM|LINK
Hey there -
I'm encountering the same issue. What is the proper setting for the MIME type? By the way, are you generating a .dotx file or a .docx file? It .docx, how did you do it?
mvcNewbie
Member
6 Points
5 Posts
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
Mar 23, 2012 01:56 AM|LINK
Hi Patrick,
The MIME type I used is this: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
I used it for docx but should work for dotx too.
adi.jurubita
Member
2 Points
5 Posts
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
May 08, 2012 02:24 PM|LINK
hello, how did you managed to make the code on the msdn page work. I tryed but with no effect on the document (dotx) created. It still haves the placeholders, no text from the XML. thanks..
mvcNewbie
Member
6 Points
5 Posts
Re: Dynamically built word document (.docx) using open XML sdk is corrupt when saved and opened f...
May 08, 2012 02:32 PM|LINK
Hi Adi,
All I did was to follow the steps given in that link. No modifications to that. You may be missing something. May not be linking the fields properly. Just check the XML being generated once and check if the name of the tags in the XML match the name of the placeholders in your template.