Word document with document protection - Restricted access

Dear Team,
Am using Aspose.word 22.12 currently, when am trying to access word document which as sensitivity label as internal - am getting an error message as “Unknown file format”

Please use the attached file and try

Aspose.Words.Document anDoc = new Aspose.Words.Document(<filepath>);

Please let me know, how to proceed showing some specific error message instead of showing generic message.
Note: Upon stack trace " at Aspose.Words.DigitalSignatures.DigitalSignatureUtil.a(GK a, String b)" am seeing this message.
Protectedtest.docx (89 KB)

Thank you

@Rajeshrv Unfortunately, Aspose.Words does not support direct loading of documents protected with sensitivity labels. To load such documents, you should first decrypt it and then feed to Aspose.Words.

Thank you for quick reply.
Currently I do not have options which could tell me that a particular document is to be decrypted or not. Is there a way in Aspose which could help me to check it at least based on some error messages.

@Rajeshrv You can use FileFormatUtil to detect encrypted documents. For example:

FileFormatInfo info = FileFormatUtil.DetectFileFormat(@"C:\Temp\in.docx");
Console.WriteLine(info.LoadFormat);
Console.WriteLine(info.IsEncrypted);

Thank you was able to proceed with the FileFormatInfo check.

1 Like