Search Results for

    Show / Hide Table of Contents

    Class WordDocumentProtectionSettings

    Represents settings for protecting a Word document.

    Inheritance
    System.Object
    WordDocumentProtectionSettings
    Namespace: IronWord.Models
    Assembly: IronWord.dll
    Syntax
    public class WordDocumentProtectionSettings : Object

    Use WordDocumentProtectionSettings to lock down a Word document so readers can open it but cannot freely change it. It gathers the protection mode, an optional password, and the formatting and region rules that decide what editing the document still permits, giving you one object to describe how a file is protected.

    You construct the settings and apply them when you save a protected document. The simplest path is the constructor that takes a ProtectionType and a password, which sets the protection level and the unlock secret in one step; the parameterless constructor lets you fill the properties individually instead. Either way the configured object describes the restrictions the saved file enforces.

    The Type property is a ProtectionType that names the protection mode, and Password holds the secret a reader needs to lift the restriction. RestrictFormatting toggles whether formatting changes are blocked, while AllowedStyles is a read-only List<string> of the style names that remain editable when formatting is restricted, so you can permit a known set of styles and freeze the rest. UnprotectedRegions is a read-only List<UnprotectedRegion> marking the spans that stay editable inside an otherwise locked document, each region pinned by a start and end ContentElement. Add the styles and regions you want to leave open, set the type and password, and the saved document applies exactly those exceptions to the protection.

    using IronWord.Models;
    
    var protection = new WordDocumentProtectionSettings(
        ProtectionType.ReadOnly, "secret");
    protection.RestrictFormatting = true;

    The edit text how-to covers changing document content, the edit text example shows an edit in code, and the document element tutorial shows the element model that unprotected regions point into.

    Constructors

    WordDocumentProtectionSettings()

    Initializes a new instance of the class.

    Declaration
    public WordDocumentProtectionSettings()

    WordDocumentProtectionSettings(ProtectionType, String)

    Initializes a new instance of the class with the specified type and password.

    Declaration
    public WordDocumentProtectionSettings(ProtectionType type, string password)
    Parameters
    Type Name Description
    ProtectionType type

    The type of protection.

    System.String password

    The protection password.

    Properties

    AllowedStyles

    If formatting restrictions are applied, this collection determines which styles are allowed.

    Declaration
    public List<string> AllowedStyles { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<System.String>

    Password

    Gets or sets the password used for protection. If null, no password is required to unprotect the document.

    Declaration
    public string Password { get; set; }
    Property Value
    Type Description
    System.String

    RestrictFormatting

    Gets or sets a value indicating whether formatting restrictions are applied.

    Declaration
    public bool RestrictFormatting { get; set; }
    Property Value
    Type Description
    System.Boolean

    Type

    Gets or sets the type of protection applied to the document.

    Declaration
    public ProtectionType Type { get; set; }
    Property Value
    Type Description
    ProtectionType

    UnprotectedRegions

    Gets or sets a list of sections or content regions that are exempt from protection.

    Declaration
    public List<UnprotectedRegion> UnprotectedRegions { get; }
    Property Value
    Type Description
    System.Collections.Generic.List<UnprotectedRegion>
    ☀
    ☾
    Downloads
    • Download with NuGet
    • Start for Free
    In This Article
    Back to top
    Install with NuGet