Last post May 08, 2012 02:32 PM by mvcNewbie
Nov 24, 2011 11:17 PM|mvcNewbie|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:
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.
Nov 25, 2011 08:34 AM|Jure.Les|LINK
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.
Dec 20, 2011 03:04 AM|mvcNewbie|LINK
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??
Dec 20, 2011 07:13 AM|Jure.Les|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.
Dec 21, 2011 12:56 PM|mvcNewbie|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!!
Mar 23, 2012 01:50 AM|patrickgeiger|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?
Mar 23, 2012 01:56 AM|mvcNewbie|LINK
The MIME type I used is this: "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
I used it for docx but should work for dotx too.
May 08, 2012 02:24 PM|adi.jurubita|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..
May 08, 2012 02:32 PM|mvcNewbie|LINK
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.