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

Free Support Forum - aspose.com

How to check protection type applied to document using .NET

Hi,

I have a dotx template where Editing restrictions have been set to allow Filling in forms. However, protection hasn’t been enforced. Please see input.dotx inside Docs.zip.

I’m running the following code on it:
var doc = new Document(“d:/input.dotx”);
doc.Save(“D:/output1.docx”);
doc.Protect(doc.ProtectionType);
doc.Save(“D:/output2.docx”);

In output1.docx these options haven’t changed (restrictions set but not enforced).
It looks like ProtectionType on Document only holds the restrictions that have been enforced. So in this case it’s NoProtection. Protecting the document with this protection type removes the restrictions completely (please see output2.docx).

Based on output1, it looks like the information about restrictions is present somewhere in the document. Is there a way to access it? If not, would you be able to provide one?

Thanks,
Michał

Docs.zip (61.0 KB)

@acturisaspose

The document is not protected. You are facing the expected behavior of Aspose.Words. However, the Section.ProtectedForForms property is set for your input.dotx. You can get its value as shown below.

var doc = new Document(MyDir + "input.dotx");
Console.WriteLine(doc.Sections[0].ProtectedForForms);