officefileapi-devexpress-dot-xtrarichedit-dot-api-dot-native-dot-document-3d6178fa.md
Removes document protection.
Namespace : DevExpress.XtraRichEdit.API.Native
Assembly : DevExpress.RichEdit.v25.2.Core.dll
NuGet Package : DevExpress.RichEdit.Core
void Unprotect()
Sub Unprotect
The Unprotect method removes document protection without prompting or password entry. To prompt end-users with a password, execute the UnprotectDocumentCommand command.
The Document.IsDocumentProtected property indicates whether the document is protected.
using (var wordProcessor = new RichEditDocumentSever())
{
wordProcessor.LoadDocument("Documents//Grimm_Protected.docx");
Document document = wordProcessor.Document;
if (document.IsDocumentProtected == true)
{
// Unprotect the document
document.Unprotect();
// Insert a comment indicating that the document can be edited
document.Comments.Create(document.Paragraphs[0].Range,"Admin");
SubDocument commentDocument = document.Comments[0].BeginUpdate();
commentDocument.InsertText(commentDocument.CreatePosition(0),
"Document is unprotected. You can modify the document.");
commentDocument.EndUpdate();
}
}
Using wordProcessor = New RichEditDocumentSever()
wordProcessor.LoadDocument("Documents//Grimm_Protected.docx")
Dim document As Document = server.Document
If document.IsDocumentProtected = True Then
' Unprotect the document
document.Unprotect()
' Insert a comment indicating that the document can be edited
document.Comments.Create(document.Paragraphs(0).Range,"Admin")
Dim commentDocument As SubDocument = document.Comments(0).BeginUpdate()
commentDocument.InsertText(commentDocument.CreatePosition(0), "Document is unprotected. You can modify the document.")
commentDocument.EndUpdate()
End If
End Using
The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Unprotect() 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#L64
// Unprotect the document.
document.Unprotect();
word-document-api-examples/VB/CodeExamples/ProtectionActions.vb#L54
' Unprotect the document.
document.Unprotect()
' Create a comment related to the first paragraph.
See Also