Back to Devexpress

Document.Protect(String, DocumentProtectionType) Method

officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-dot-protect-x28-system-dot-string-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-documentprotectiontype-x29.md

latest3.8 KB
Original Source

Document.Protect(String, DocumentProtectionType) Method

Enforces document protection and sets the specified password.

Namespace : DevExpress.XtraRichEdit.API.Native

Assembly : DevExpress.RichEdit.v25.2.Core.dll

NuGet Package : DevExpress.RichEdit.Core

Declaration

csharp
void Protect(
    string password,
    DocumentProtectionType protectionType
)
vb
Sub Protect(
    password As String,
    protectionType As DocumentProtectionType
)

Parameters

NameTypeDescription
passwordString

A password string.

| | protectionType | DocumentProtectionType |

One of the DocumentProtectionType enumeration values.

|

Remarks

Calling the Protect method restricts end-users from modifying the document. The password specified as the Protect parameter is used to unprotect the document in the UI using the Unprotect Document dialog.

The Document.IsDocumentProtected property indicates whether the document is protected.

To remove protection in code, call the Document.Unprotect method. It unprotects the document, ignoring the password.

The Protect method to not require user input. To allow users to create a password to protect the document, execute the ProtectDocumentCommand command instead.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Protect(String, DocumentProtectionType) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

word-document-api-examples/CS/CodeExamples/ProtectionActions.cs#L30

csharp
// Protect the document with a password.
document.Protect("123", DocumentProtectionType.ReadOnly);

word-document-api-examples/VB/CodeExamples/ProtectionActions.vb#L29

vb
' Protect the document with a password.
document.Protect("123", DevExpress.XtraRichEdit.API.Native.DocumentProtectionType.[ReadOnly])
' Create a comment related to the first paragraph.

See Also

IsDocumentProtected

Document Interface

Document Members

DevExpress.XtraRichEdit.API.Native Namespace