We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Document Protection dosent seam to work for docx documents

Document Protection doesn’t seam to work for docx documents…
First I load up a blank docx document created with MS Office 2007.

string templatePath = this.MapPath("bin") + @"\..\templates\blank.docx";

Then I create the Document and Document builder classes…

Document doc = new Document(templatePath);
DocumentBuilder builder = new DocumentBuilder(doc);

Then I inserted some html using the DocumentBuilder classes InsertHTML method.
Then I used this code to lock the document:

doc.Protect(ProtectionType.ReadOnly, "document!");

Then I sent the document to the user with this code.

doc.Save("TestDocument.docx", SaveFormat.Docx, SaveType.OpenInWord, this.Response);

This I assume should lock the document. But when the document is brought up in word 2007 on the target system the document is locked and can’t be modified initially. But if the “Stop Protection” button is pressed it just unlocks the document, It never asks for a password and the user can edit the document with no problems.
Have I done something wrong?
I have attached a sample document…
Bryan Grossman


Thanks for your request. I tried to protect DOCX document and it seems that all works fine on my side. See the attachment. I created this document using the following code.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
for (int i = 0; i < 20; i++)
doc.Protect(ProtectionType.ReadOnly, "test");
doc.Save(@"302_100117_bryangrossman\out.docx", SaveFormat.Docx);

Also note that export/import of DOCX files is currently in beta.

Best regards.