Sufo
Sufo

Reputation: 27

Without opening, how can I read OpenXML document properties of password protected files programmatically?

I have an application which generates passwords for .xlsx files algorithmically based on custom document properties. Persistence of the properties is ensured by setting the openxmlencryptproperty key to false. As such, the file content is password protected, but the properties are visible (via explorer).

The intended functionality is that the password is recalculated from the properties before attempting to open the workbook. Unfortunately, the only methods I can find to get at these properties involve opening the workbook (either via System.IO.Packaging or OpenXml.Packaging).

Clearly explorer is able to read these properties without actually opening the file. How can I replicate this behaviour in C#? (perhaps invoking an instance of explorer?).

Upvotes: 0

Views: 336

Answers (1)

Sufo
Sufo

Reputation: 27

After various attempts to leverage the properties using the Microsoft.WindowsAPICodePack-Shell API, the only way I was able to get to custom properties was via the StructuredStorage API, as demonstrated in the snippet provided in the second part of this accepted answer to a similar question.

Upvotes: 1

Related Questions