Protecting Documents

Skip to end of metadata
Go to start of metadata
When a document is protected, the user can make only limited changes, such as adding annotations, making revisions, or completing a form.

Even if a document is protected with a password, Aspose.Words does not require the password to open, modify or unprotect this document.

When you use Aspose.Words to protect a document, you have an option of keeping the existing password or specifying a new password.

If you need to make sure the document is really protected from changes, consider digitally signing the document. Aspose.Words supports detecting digital signatures for DOC, OOXML and ODT documents. Aspose.Words also preserves a digital signature applied to the VBA project (macros) contained in a document. For further details see the Working with Digital Signatures article.

Documents protected in Microsoft Word can be easily unprotected even by users without a password. When a document is protected, it can be opened in Microsoft Word, saved as RTF or WordprocessingML document and then the protection password can be removed using Notepad or any plain text editor. Then, the user can open the document again in Microsoft Word and save as an unprotected DOC.

Protecting a Document
Use the Document.Protect method to protect a document from changes. This method accepts a ProtectionType parameter and optionally a password by passing one as the second parameter Document.Protect.

Example

Shows how to protect a document.

C#
Document doc = new Document();
doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
 
Visual Basic
Dim doc As New Document()
doc.Protect(ProtectionType.AllowOnlyFormFields, "password")
 

Unprotecting a Document
Calling Document.Unprotect unprotects the document even if it has a protection password.

Example

Shows how to unprotect any document. Note that the password is not required.

C#
doc.Unprotect();
 
Visual Basic
doc.Unprotect()
 

Getting the Protection Type
You can retrieve the type of document protection by getting the value of the Document.ProtectionType property.

Example

Shows how to get protection type currently set in the document.

C#
Document doc = new Document(MyDir + "Document.doc");
ProtectionType protectionType = doc.ProtectionType;
 
Visual Basic
Dim doc As New Document(MyDir & "Document.doc")
Dim protectionType As ProtectionType = doc.ProtectionType
 
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.