ProtectionType

ProtectionType enumeration

Protection type for a document.

public enum ProtectionType

Values

NameValueDescription
AllowOnlyComments1User can only modify comments in the document.
AllowOnlyFormFields2User can only enter data in the form fields in the document.
AllowOnlyRevisions0User can only add revision marks to the document.
ReadOnly3No changes are allowed to the document. Available since Microsoft Word 2003.
NoProtection-1The document is not protected.

Examples

Shows how to turn off protection for a section.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);
builder.Writeln("Section 1. Hello world!");
builder.InsertBreak(BreakType.SectionBreakNewPage);

builder.Writeln("Section 2. Hello again!");
builder.Write("Please enter text here: ");
builder.InsertTextInput("TextInput1", TextFormFieldType.Regular, "", "Placeholder text", 0);

// Apply write protection to every section in the document.
doc.Protect(ProtectionType.AllowOnlyFormFields);

// Turn off write protection for the first section.
doc.Sections[0].ProtectedForForms = false;

// In this output document, we will be able to edit the first section freely,
// and we will only be able to edit the contents of the form field in the second section.
doc.Save(ArtifactsDir + "Section.Protect.docx");

See Also