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.
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.
If you need to make sure the document is really protected from changes, consider digitally signing the document. Aspose.Words does not support digital signatures for a complete Microsoft Word document at the moment. Aspose.Words will only preserve a digital signature applied to the VBA project (macros) contained in a document.
Protecting a Document
Use the Document.Protect method to protect a document from changes. This method accepts a ProtectionType parameter and optionally a password.
Example ProtectDocument
Shows how to protect a document.
[C#]
Document doc = new Document();
doc.Protect(ProtectionType.AllowOnlyFormFields, "password");
[Visual Basic]
Dim doc As Document = New Document()
doc.Protect(ProtectionType.AllowOnlyFormFields, "password")
[Java]
Document doc = new Document();
doc.protect(ProtectionType.ALLOW_ONLY_FORM_FIELDS, "password");
Unprotecting a Document
Calling Document.Unprotect unprotects the document even if it has a protection password.
Example UnprotectDocument
Shows how to unprotect any document. Note that the password is not required.
[C#]
doc.Unprotect();
[Visual Basic]
doc.Unprotect()
[Java]
doc.unprotect();
Getting the Protection Type
You can retrieve the type of document protection by getting the value of the Document.ProtectionType property.
Example GetProtectionType
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 Document = New Document(MyDir & "Document.doc")
Dim protectionType As ProtectionType = doc.ProtectionType
[Java]
Document doc = new Document(getMyDir() + "Document.doc");
int protectionType = doc.getProtectionType();