Unlock and lock a Word document for form protection without password

Category: open xml format sdk


Peter Karlström on Fri, 16 Nov 2018 10:55:11


I want to be able to unlock and lock a Word document which has forms protection without a password.
All information I find on the subject involvs setting a password which makes it very complicated.

My customer wants form protected Word documents for user convenience, not security reasons.

How is this done with Open XML 2.5?

Best Regards Peter Karlström Midrange AB, Sweden


Yuki Lou-MSFT on Mon, 19 Nov 2018 06:41:17

Hi Peter,

You can try the following code to unlock a Microsoft .docx document:


For more information, please review the following link:

How can I unlock a Microsoft .docx document?

Hopefully it helps you.

Best Regards,


Yuki Lou-MSFT on Tue, 20 Nov 2018 07:23:40

Hi Peter,

Thanks for your asking. Did you resolve your issue? If the post helps you, you can mark it as answer and close the post.

Thank you for understanding. If you have any question, or update, please feel free to let us know.

I wish you a happy life!

Best Regards,


Peter Karlström on Tue, 20 Nov 2018 09:56:03

Hi Yuki

Thanks for your reply.
I have looked into this, but your sample is no code I can use. This is markup language and is not executable.

Also, the link you provided doesn't explain how to check for document protection type or status.

I need help with checking if documentprotection is present and active in the opened document and if it is, what type of protection it is.Code in VB or C# would be a great help.

Peter Karlström on Tue, 20 Nov 2018 10:39:54

Here is the solution:

        Using doc As WordprocessingDocument = WordprocessingDocument.Open(<fullpath to document>, True)
            Dim mainPart As DocumentFormat.OpenXml.Packaging.MainDocumentPart = doc.MainDocumentPart
            Dim pData As DocumentProtection = doc.MainDocumentPart.DocumentSettingsPart.Settings.ChildElements.First(Of DocumentProtection)()
            If Not pData Is Nothing Then
                If pData.Edit.Value = DocumentProtectionValues.Forms Then
                    If pData.Enforcement Then
                        pData.Enforcement = False
                        pData.Enforcement = True
                    End If
                End If
            End If
        End Using