locking/unlocking bookmarks dynamically

Suppose I'd like to allow users to edit only certain fields of my Word document, according to their user group. One option that I found is to always programmatically protect the document with a password and then allow access to some specific bookmarks, as shown by the following code:

object editorType = Word.WdEditorType.wdEditorEveryone;

this.bookmark1.Range.Editors.Add(ref editorType);

The question is: how do I remove this "edition permission" of the bookmark When the document is saved and other user opens it, the bookmark is still editable...

Thanks a lot,
-- AFurtado




Answer this question

locking/unlocking bookmarks dynamically

  • Misswing

     Hi Andre,

    When you add an editor, you are getting an object that represents a permission for the group/id you are adding (Word.WdEditorType.wdEditorEveryone). 

    Have you tried deleting that permission before closing the document (or whenever that permission is no longer required)

    Example:

    private void RemoveEditorPermissions(Bookmark bm)
    {
      for(int i = 0; i < bm.Range.Editors.Count; i++)
      {
         object editorIndex = i + 1;  //1-based index
         bm.Range.Editors.Item(ref index).Delete();

      }
    }

    Regards,

    Daniel Molina

     



  • Ethan Efren

    Thanks Daniel, it worked! Two remarks:

    - It's better to use the code in the document load, in order to remove all editor permissions of all bookmars, then assign the permissions only to the desired bookmarks. Otherwise one may call the code while closing the document but it may not be saved.

    - In the above code, replace index by editorIndex :)

    []s
    -- AFurtado



  • locking/unlocking bookmarks dynamically