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

Free Support Forum - aspose.com

How do determine if a document is password protected

How can I tell whether a Word document is password-protected or not? I understand that the doc.BuiltInDocumentProperties.Security propery isn't necessarily accurate because Microsoft doesn't alway set this property. Are there any viable alternatives?

Thanks.

Jim McFadden / Unum

Hello

<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request.

1. If you specify “Password to open” - BuiltInDocumentProperties.Security = PasswordProtected

You should check LoadFormat using DetectFileFormat method:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/howto-detect-the-file-format.html

If returned format is OoxmlEncrypted or DocEncrypted then the document is PasswordProtected.

2. If you specify “Password to modify” - BuiltInDocumentProperties.Security = ReadOnlyEnforced

In this case you can use WriteProtection property to retrieve this protection status:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/aspose.words.document.writeprotection.html

3. If you check “Read-only recommended” checkbox - BuiltInDocumentProperties.Security = ReadOnlyRecommended

4. And if you protect your document and allow only Comments - BuiltInDocumentProperties.Security = ReadOnlyExceptAnnotations

In these two cases you can use Document.ProtectionType property:

http://www.aspose.com/documentation/.net-components/aspose.words-for-.net-and-java/protecting-documents.html

Best regards,