User-863338713 posted
but after save, bookmark is vanished.
bookmark name must not be vanished.
please help me. see my code below.
--------------------------
object fileName = Server.MapPath("word/test.docx");
object readOnly = false; object isVisible = true;
object missing = System.Reflection.Missing.Value;
// create instance of Word
Microsoft.Office.Interop.Word.Application _oWordApp = new Microsoft.Office.Interop.Word.Application();
// create instance of Word document Document oWordDoc = new Document();
// open word document
oWordDoc = _oWordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref readOnly, ref missing, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
oWordDoc.Activate();
// debug to see that I can write to the document
//_oWordApp.Selection.TypeText("This is the text that was written from the C# program! ");
// _oWordApp.Selection.TypeParagraph();
// Example of writing to bookmarks each bookmark will have exists around it to avoid null
if (oWordDoc.Bookmarks.Exists("vendorName")) {
// set value for bookmarks
object oBookMark = "vendorName";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "Genesis Software Development";
oBookMark = "vendorAddress";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "3333 West 3rd Street";
oBookMark = "vendorCity";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "Austin";
oBookMark = "vendorState";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "TX";
oBookMark = "vendorZip";
oWordDoc.Bookmarks.get_Item(ref oBookMark).Range.Text = "75235"; }
// save the document
_oWordApp.Documents.Save(ref missing, ref missing);
// _oWordApp.Documents.Save(NoPrompt: true, OriginalFormat: true);
// close the applicationq
((_Application)_oWordApp).Quit(SaveChanges: false, OriginalFormat: false, RouteDocument: false);
System.Runtime.InteropServices.Marshal.ReleaseComObject(_oWordApp);