Document protection

The Password property, if set, enables document protection from opening by encrypting it with specified password. However, almost all WordProcessing formats support a document protection from writing, which is completely different from opening. Document protection, like document encoding, also implies a password as a form of key, but it also supports different levels of protection: some of them allow only read-only mode, other allow to edit form-fields etc.

GroupDocs.Editor allows to apply the document protection via the Protection property in the WordProcessingSaveOptions class. By default this property has a NULL value, which means that GroupDocs.Editor will not apply the protection to the document.

The Protection property has a WordProcessingProtection type. This type is a class, which, it turn, consists of two properties: Password and a ProtectionType.

WordProcessingProtection class has two constructors. First one is parameterless, it sets both class properties to their default values. If user will use this constructor, and then will not set values to the properties in class instance, the protection will not be applied to the document. Second constructor, in counterpart, has two parameters, which set values to the properties; so, when using this constructor, there is no need to use properties at all.

The Password property is responsible for setting a password for the document protection. By default it is NULL — protection is not applied. If user wants to apply the document protection, he needs to assign some string to this property (through constructor or property itself); otherwise protection will not be applied regardless from the value of the ProtectionType property.

ProtectionType property has type WordProcessingProtectionType, which is a simple enum, and value of this enum determines the level of protection. By default enum has a NoProtection value, which means that no protection will be applied. Other values are:

  1. AllowOnlyRevisions — User can only add revision marks to the document.
  2. AllowOnlyComments — User can only modify comments in the document.
  3. AllowOnlyFormFields — User can only enter data in the form fields in the document.
  4. ReadOnly — No changes are allowed to the document.

Take a note that both the properties Password and a ProtectionType are bound to each other. If user set a valid non-NULL not-empty Password, but the ProtectionType property has a WordProcessingProtectionType. NoProtection value, the protection will not be applied. And vice versa, if ProtectionType property has a AllowOnlyFormFields value, for example, but Password is NULL or empty string, then the protection will not be applied too.

More resources

GitHub Examples

You may easily run the code above and see the feature in action in our GitHub examples:

Free Online App

Along with full-featured .NET library we provide simple but powerful free Apps.
You are welcome to edit your Microsoft Word (DOC, DOCX, RTF etc.), Microsoft Excel (XLS, XLSX, CSV etc.), Open Document (ODT, OTT, ODS) and other documents with free to use online GroupDocs Editor App.