Mahmoud Elgindy
Mahmoud Elgindy

Reputation: 114

Open protected word document with OpenXML

I have searched every where but, I can't found any answer. All posts and discussions are about creating protected one but nothing for open it.

I have protected DOCX and DOC documents in my c# program and want to open them programmatically using OpenXML 2.5.

I have opened them using Office interlope as it has password parameter. But it's very slow with large documents number.

Can i open password protected word documents using OpenXml ? How ?

Thanks.

Upvotes: 4

Views: 2537

Answers (2)

Yeshurun Kubi
Yeshurun Kubi

Reputation: 136

There is a way to release the lock using OpenXml, by canceling the protection. Found the answer Here.

WordprocessingDocument doc = WordprocessingDocument.Open(filePaths[i], true);
doc.ExtendedFilePropertiesPart.Properties.DocumentSecurity = new DocumentSecurity("0");
doc.ExtendedFilePropertiesPart.Properties.Save();
DocumentFormat.OpenXml.Wordprocessing.DocumentProtection dp =
doc.MainDocumentPart.DocumentSettingsPart
.Settings.ChildElements.First<DocumentFormat.OpenXml.Wordprocessing.DocumentProtection>();

Upvotes: 0

Cindy Meister
Cindy Meister

Reputation: 25663

Password protected documents (documents saved with a password) are not Zip packages, they're binary files. If you think about it, the reason is obvious: a Zip package of XML files is human-readable - not secure. So you can't manipulate password protected Word documents via the Open XML file format - it's simply not there.

Upvotes: 2

Related Questions