We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Protect / Unprotect

Hello,

I'm using the protect / unprotect methods on Word.Document
When a protected (by aspose) document is loaded in word, in some situation I need to unprotect it.

When I use Word Object model, I can call:
this.Document.Protect(Word.WdProtectionType.wdAllowOnlyReading);
Then I can call:
this.Document.Unprotect();

I can do the same with aspose:
this.Document.Protect(Aspose.Words.ProtectionType.ReadOnly);
But when using Word Object model to unprotect, an exception is thrown :

System.Runtime.InteropServices.COMException (0x800A156D): The password is incorrect.
at Microsoft.Office.Interop.Word.DocumentClass.Unprotect(Object& Password)
at WordLink.AddinModule.unlock(Boolean unlock)

I need to remove the read-only protection juste to change some link, how could I do that ?

I'm using Aspose.Word v13.4.0.0

Thank you

Hi Fabrice,


Thanks for your inquiry. Please note that Aspose.Words tries to mimic the same behavior as MS Word do. Please open the protected document in MS Word and check the readony protection. I suggest you pelase use the latest version of Aspose.Words v 13.6.0.

If you face any issue with Aspose.Words, please create a simple application (for example a Console Application Project) that helps us reproduce the same problem on our end and attach it here for testing. Unfortunately, it is difficult to say what the problem is without the Document(s) and simplified application. We need your Document(s) and simple project to reproduce the problem. As soon as you get these pieces of information to us we’ll start our investigation into your issue.

On this point Aspose.Word doesn’t mimic MS Word.


I’ve read in other topics on this forum that when a password is not provided, aspose.word automatically generate a random password. This is not the way MS Word work. With this info, I’ve found a solution to my problem: provide an empty password to aspose.word.

If I write this in MS Word:
this.WordDocument.Protect(Word.WdProtectionType.wdAllowOnlyReading);
The equivalent with aspose.word is:
this.AsposeWordDocument.Protect(Aspose.Words.ProtectionType.ReadOnly, string.Empty);

I need to specify an empty password to get the same behavior than in MS Word.

Hi Fabrice,


Thanks for your feedback. It is nice to hear from you that you have solved your problem. Please read following detail about Document.Protect methods for your kind reference.

Document.Protect Method (ProtectionType) : Protects the document from changes without changing the existing password or assigns a random password.

When you protect a document, and the document does not have a protection password, this method assigns a random password that makes it impossible to unprotect the document in Microsoft Word, but you still can unprotect the document in Aspose.Words as it does not require a password when unprotecting.

Document.Protect Method (ProtectionType, String) : Protects the document from changes and optionally sets a protection password. The second parameter is password to protect the document with. Specify null or empty string if you want to protect the document without a password.

Hope this helps you. Please let us know if you have any more queries.