Search code examples
c#.netms-wordoffice-interop

How to Disable Header section in Word Doc for editing using word interop c#


I have Test.dotx file having one picturebox and 2 text fields in Header section (Header-footer).

When I create Test.DocX from Test.dotx file, i want Header part of file to be locked for editing i.e. user must not be able to write or delete from header section of document(Test.DocX).

I am using word.interop for this purpose. I have given lock to Content Controls in header via.

  cc.LockContentControl = true;
  cc.LockContents = true;

This disables only controls but other area in header remains Editable. I want to lock whole header section.


Solution

  • Select everything in the document the user is allowed to edit. Display Developer/Protect/Restrict editing (names may vary depending on version of Word), activate the checkboxes in Step 2 for "Read-only" editing. When you're done, click the button to start enforcing protection. As long as you did not select the text in the header it will be protected (locked).

    In order to find out the object model objects, properties and methods, record the steps in a macro.