Edit saved Microsoft Word document in C # / Asp.net

I'm not sure if this is possible, and every time I have searched, I cannot find a clear answer. I am saving a Microsoft Word document in a SQL Server 2008 Byte[]

table. Basically, I just convert the file to and write it to the table. This document is a "template". The file is a form that the user must fill out. I am wondering, after reading this file from SQL Server and before opening it to the user, is there a way to autopopulate some of the fields in the form for the user? For example, if I know the user's address already, can I auto-populate the address field in the template for them?

I know that using Microsoft.Office.Interop.Word

, I can search the document for bookmarks and insert data into the bookmark. However, as far as I know, you cannot use Microsoft.Office.Interop.Word

to openByte[].

Is there anyway to complete what I was looking for?


source to share

2 answers

If you want to use OpenXML you can do it like this,

//Load your byte[] array into memory stream and then 
WordprocessingDocument doc = WordprocessingDocument.Open(stream, true);


You can do what you are trying to achieve using OpenXML without setting a server side word. More resources on OpenXMl can be found at http://openxmldeveloper.org/ . And the open xml sdk can be downloaded from here .



I think the general steps are to

1) Save the file to the user's local hard drive with a file name based on the template, but with a .doc extension.

2) Open the file with interop but keep it invisible.

3) Fill in the fields with bookmarks.

4) Show it to the user.



All Articles