views:

41

answers:

2

We want to store Microsoft Word templates in our database. Then we wish to allow the user to edit the template files and then store them back to the database. What is the best strategy to use in this situation?

Is this possible if we have Word running in a separate process? i.e. not hosted in our application. If so would this involve monitoring a file on disk for changes, as that sounds horrible. With this thinking we would like to open the file from a memory stream and never let it touch the disk. But we are open to suggestions.

The problem with writing it to disk could be:

Once word opened from a temp file or folder the user created a new document without saving, then did not close word. (so we couldn't tell when the process finished) Or deleted the temp file or folder. i would like the solution where i could control word, perhaps host it in app. i would like to not have to write it to a file. any ideas?

+1  A: 

For editing, I would download file into temp folder, and then in your application I will launch Word using Automation:

Application app = new Application();
app.Visible = true;
Document doc = app.Documents.Open("path to temp file");

These lines will launch Word and open your file. Then, you can monitor what is happening to your document and Word instance, and when user saves it, just upload file back to database.

You can always hide and/or close this instance by executing following lines:

app.Visible = false;
app.Quit();

Please note, that you have to reference Microsoft.Office.Interop.Word assembly

TTRider
i've edited the question to address problems with this answer, any more ideas?
Aran Mulholland
I see the problem. let me think about it. I know that that is a stretch, but can you use Sharepoint? or http://office.live.com or http://docs.com ?All 3 will allow you to store and edit documents i browser or in Word.Since Word can use non-file system storage in their scenarios, makes me think it is possible in yours.Again, let me dig for a while ....
TTRider
A: 

The only way I could think of downloading the document to memory and avoiding disk altogether is to create a ram disk, but that could get pretty complex, and requires an admin installation to install the ramdisk driver.

Regarding the process and file monitoring, you could launch word.exe with the necessary parameters to open the document, but you'd still have to monitor the file for changes and the external process to know when the user exits word. If the user never saves the file or closes word, there's not much you can do. Word does not expose an out of process event model.

Chris