Detect password protection for the MS Word document

Hello Aspose team!

I have a question about password-protected MS Word files and Aspose.Words for .NET. I know that Aspose.Words allows to open the password-protected encrypted document: Opening Encrypted Documents.

However I’m wondering does Aspose.Words allows to detect the password protection for the specific document without opening it? In other words, is it possible, without knowing the password, to detect, is the specific document password-protected, and if yes, is my password valid? Aspose.Pdf allows such functionality: How to - determine if the source PDF is password protected.

So I want to know, is there something similar in Aspose.Words.

Thanks in advance!

With best regards,
Denis Gvardionov

Hi Denis,

Thanks for your inquiry. FileFormatInfo.IsEncrypted property returns true if the document is encrypted and requires a password to open.

This property exists to help you sort documents that are encrypted from those that are not. If you attempt to load an encrypted document using Aspose.Words without supplying a password an exception will be thrown. You can use this property to detect whether a document requires a password and take some action before loading a document, for example, prompt the user for a password.

Please check following code example for your kind reference.

FileFormatInfo info = FileFormatUtil.DetectFileFormat(MyDir + "Document.doc");
Console.WriteLine("The document format is: " + FileFormatUtil.LoadFormatToExtension(info.LoadFormat));
Console.WriteLine("Document is encrypted: " + info.IsEncrypted);