Table of Contents

Method SetDocumentProtection

Namespace
DocWright.Dom.Editing
Assembly
DocWright.Dom.dll

SetDocumentProtection(WordDocument, DocumentPosition, Action<DocumentProtection>)

Changes the document's protection settings as one undoable edit. change is given a copy of the settings as they are and changes it; the copy then takes the settings' place, and undo puts the settings back exactly as they were, password material included. No paragraph changes: the layout is not affected.

public static DocumentEdit SetDocumentProtection(this WordDocument document, DocumentPosition at, Action<DocumentProtection> change)

Parameters

document WordDocument

The document.

at DocumentPosition

A position in the document (where the edit's caret stays).

change Action<DocumentProtection>

Changes the copy of the settings.

Returns

DocumentEdit

The edit (empty when change changed nothing).

Remarks

The settings are modelled, not enforced: this records what the document asks of a program that opens it. DocWright.Cryptography's DocumentProtectionHash.StartEnforcing and StopEnforcing change a DocumentProtection the way Word's Restrict Editing does, and are what to call from change to start or stop protection with a password.

Exceptions

ArgumentNullException

document or change is null.

ArgumentException

at is not in document.