In ASP.NET, how do I determine the password in a Word 2003 or 2007 file?

My users upload password-protected Word documents to our document management system. I would like to add a check in order to verify the password and refuse to download if it has a password.

Word automation — using COM interoperability — is out of the question because this is a server-side application.

+6
ms-word ms-office docx
source share
3 answers

Unfortunately, it is not available directly from .NET or DSOFile.dll , but you can create a wrapper in .NET to read the PIDSI_DOC_SECURITY properties of any Office file to find out if it is password protected or not without opening the document. There are a number of C ++ samples that can be ported using the iPropertyStorage definition.

A wrapped example is on TechTarget , but the shell seems inaccessible.

+5
source share

I think this will depend on the version of Microsoft Word. Older versions of Word (prior to 2007) will require some COM interaction because they are not saved in open format. Nothing you can do to get around this, and I feel your disappointment that you are installing Office on a web server. In addition, I believe that the only way to detect password protection is to try to open / remove protection from the file and catch a certain exception (you may have to additionally evaluate the error code in this exception). Not beautiful!

However, for new versions of the word (2007+) saved in the open DOCX format ( Standard ECMA-376 ), you can examine the XML and check the existence of the DocumentProtection element with the w:enforcement attribute set to "on" ...

 <w:DocumentProtection w:edit="read-only" w:enforcement="on" w:unprotectPassword="1FC6CBEB"/> 

Note. The password recorded here is encrypted (obviously); I saved this particular document with the password "test".

+5
source share

Are you saying you want to open / study Word documents without any interaction with Office? Good luck

Perhaps your only place to start is to manually parse docx (the specification is published here ). In fact, although I would advise you to bite the bullet and use the Office internetworking libraries, because it requires much lighter weight than analyzing the document yourself. None of this is stopping you from doing this in a server application.

0
source share

All Articles