[Expand]General Information
[Expand]WinForms Controls
[Expand]ASP.NET Controls and MVC Extensions
[Expand]ASP.NET Bootstrap Controls
[Expand]ASP.NET Core Bootstrap Controls
[Expand]WPF Controls
[Expand]Xamarin Controls
[Expand]Windows 10 App Controls
[Collapse]Office File API
  Demo Application
  Redistribution and Deployment
 [Expand]Spreadsheet Document API
 [Collapse]Word Processing Document API
   Getting Started
  [Expand]Word Processing Document
  [Expand]Merge and Split Documents
   Import and Export
   Text Formatting
   Mail Merge
   Export to PDF
   Document Protection
   HTML Tag Support
 [Expand]PDF Document API
 [Expand]Excel Export Library
 [Expand]Snap Report API
 [Expand]Zip Compression and Archive API
 [Expand]Barcode Generation API
 [Expand]Unit Conversion API
 [Expand]API Reference
[Expand]Report and Dashboard Server
[Expand]eXpressApp Framework
[Expand]eXpress Persistent Objects
[Expand]CodeRush Classic
[Expand]Cross-Platform Core Libraries
[Expand]Tools and Utilities
 End-User Documentation
View this topic on docs.devexpress.com (Learn more)

Document Protection

Expanded Restrict Document Modification

You can restrict document modification using the Document.Protect method. This method sets the password, and specifies actions allowed for the protected document (the DocumentProtectionType enumeration values). The Document.IsDocumentProtected property indicates whether content modification protection is enabled.

Use the Document.Unprotect method to disable protection. Note that it unlocks the document without a password request. To prompt the user to enter a password, execute the UnprotectDocumentCommand command.


The RichEditDocumentServer protection affects only the document modification. The RichEditDocumentServer protection protects the document only against modifications.

Expanded Open and Save Password-Encrypted Files

The RichEditDocumentServer (see RichEditDocumentServer) allows you to load and save password-encrypted files.

Open an Encrypted File

Specify the RichEditDocumentImportOptions.EncryptionPassword property to decrypt a loaded file. The table below lists a chain of events raised if the EncryptionPassword property is not specified or returns an invalid password.

Event Description
RichEditDocumentServer.EncryptedFilePasswordRequested Raised if the EncryptionPassword property is not specified or returns an invalid password. Use the EncryptedFilePasswordRequestedEventArgs.Password property to specify a new password.
RichEditDocumentServer.EncryptedFilePasswordCheckFailed Raised if the EncryptedFilePasswordRequestedEventArgs.Password is set to an empty or invalid password. Handle this event to obtain the error that led to this event (EncryptedFilePasswordCheckFailedEventArgs.Error) and determine whether to prompt a user for a password (EncryptedFilePasswordCheckFailedEventArgs.TryAgain).
RichEditDocumentServer.DecryptionFailed Raised if the TryAgain property is not specified or set to false, or when the RichEditDocumentServer failed to load an encrypted file. The DecryptionFailedEventArgs.Exception property indicates the exception that led to this event.

The code sample below shows how to handle the RichEditDocumentServer.EncryptedFilePasswordRequested and RichEditDocumentServer.EncryptedFilePasswordCheckFailed events to prompt users to enter a password. If the user cancels the operation, the RichEditDocumentServer shows an exception message and cancels loading the file.


A complete code sample project is available at https://github.com/DevExpress-Examples/how-to-open-and-save-encrypted-files.

The RichEditDocumentServer.EncryptedFileIntegrityCheckFailed event occurs if the document did not pass the code verification.

Encrypt a Document with a Password

Use the Document.Encryption property to obtain the encryption options.

Call the RichEditDocumentServer.SaveDocument(String, DocumentFormat, EncryptionSettings) (see RichEditDocumentServer.SaveDocument) method overload to password-protect the document on save. Use the EncryptionSettings object properties to specify password and protection type.

Expanded Grant Permission to Users

Create Range Permissions as described in the steps below to allow certain users to edit parts of a protected document.

  1. Call the SubDocument.BeginUpdateRangePermissions method to access the document range permissions collection.
  2. Create a new RangePermission object using the RangePermissionCollection.CreateRangePermission method.

  3. Utilize the RangePermission.UserName or RangePermission.Group property to specify the user or group of users that are allowed to edit the document range (see DocumentRange)

    Make sure that the property value is equal to the target user's credentials.

  4. Add the created object to the RangePermissionCollection.

  5. Finalize the modification by calling the SubDocument.EndUpdateRangePermissions method.

  6. Enable document protection. When protection is enabled, ranges without editing permissions are read-only.

Is this topic helpful?​​​​​​​