This project has moved and is read-only. For the latest updates, please go here.

Open a resulting DocX object as a word document

Mar 17, 2013 at 6:58 PM
This is what I am doing:
  • Load a Word document into a DocX object,
  • Then do some replacements on the document.
  • After that I want to show the result to the user so that he can save the document wherever he needs.
I don't find the way of doing it apart from saving the document to disk and then opening it.

I'd like to avoid it because user can have selected several files at the same time to do the replacement and thus I should write to disk each of the resulting files.

So, is there any way to show the document from the DocX object?

Mar 18, 2013 at 9:39 AM
That's not possible with DocX. And it would be very hard to do that anyways. Basically you would need to write a Word control to be able to display document within .NET framework. Imagine that. So yes save it to disk, open word and display it to user and ask if it's OK.
Mar 28, 2013 at 8:59 AM
You could also try using

It seems to be able to load .DocX files (even convert DocX to PDF too). It's pay version thou.
Apr 25, 2013 at 3:35 PM
Hi Albertosh,

We do something similar. What we did was create our own wordmerge class that will act like a mailmerge (replace text holders with actual text from a recordset). Since this is all done within a class, we can pass in record at a time for any specified document and basically loop through the entire recordset as needed.

If it's a single document and single record we simply save the temp file and server the word document to the user.
If it's a single word document and multiple recordset, then we create a tempfulldoc.docx document and insert the mergedoc.docx file that gets replaced for each looped record.

This works perfectly for us since we don't handle 1000's of documents/records at a time.

It doesn't look like there is a way of holding a merged docx file in memory and serving that. I wouldn't recommend that either since it would be very volatile and potential for abuse. Using a temp folder/file that gets cleared after use is more reliable.

Good look and let us know what you went with.