Using Visual Studio 2010 and Microsoft Word 2010:
I have a document that Restrict Editing is enabled to Allow only "filling in forms" when editing in the document.
On the Word document I have Text Form Fields I added from the Developer tab from the Legacy Controls.
What I want to do is populate some of these Form Fields with data (like their name, address, etc...stuff I already know and already pulled from the database).
What I've tried:
using System;
using System.Configuration;
using System.IO;
using Microsoft.Office.Interop.Word;
var oWordApplication = new ApplicationClass();
object missing = System.Reflection.Missing.Value;
object fileName = ConfigurationManager.AppSettings["DocxPath"];
object newTemplate = false;
object docType = 0;
object isVisible = true;
var oWordDoc = oWordApplication.Documents.Add(fileName, newTemplate, docType, isVisible);
if (oWordDoc.Bookmarks.Exists("txtName"))
{
oWordDoc.Bookmarks["txtName"].Range.Text = "Test Field Entry from webform";
}
I'm able to find the field I want to edit but I get the following error when I try to modify the text:
You are not allowed to edit this selection because it is protected.