ProtectionType AllowOnlyFormFields Issue - .Net

Hello

I have a small problem in protecting a Word document. The piece of code ist quite simple as you can see, in the attachment. If I open the document now, I can edit anything despite the protectiontype “AllowOnlyFormFields”. If I set another protectiontype like “ReadOnly” it works without problems.

But with “AllowOnlyFormFields” I can edit the whole text, cut, paste, anything. I’m not sure if this is a mistake on my side or a problem with the .dot file/aspose.

Thanks for your help.

Hi Beat,

Thanks for your inquiry. When you use ProtectionType AllowOnlyFormFields, you can only enter data in the form fields in the document.

Could you please attach your input Word document here for testing? I will investigate the issue on my side and provide you more information.

Hi and thank you for your answer.

I’m creating the document from a .dot file. I’ll add the .dot file and the result in the attachment.

Hi Beat,

Thanks for sharing the document. I have managed to reproduce the same issue at my side. I have logged this issue as WORDSNET-8360 in our issue tracking system. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Beat,

Thanks for your patience. It is to inform you that our development team has completed the work on the issue (WORDSNET-8360) and has come to a conclusion that this issue is actually not a bug. If you try loop through all sections of your document using the following code, you will see that the first section has ProtectedForForms equals false. You have to set this property to ‘true’ to get expected result.

foreach(Section sec in doc.Sections)
{
    Debug.WriteLine(sec.ProtectedForForms);
}

Please use the following code snippet to achieve your requirements. Please let us know if you have any more queries.

Document doc = new Document(MyDir + "Neutral.dotx");
foreach(Section sec in doc.Sections)
{
    sec.ProtectedForForms = true;
}
doc.Protect(ProtectionType.AllowOnlyFormFields, "123");
OoxmlSaveOptions option = new OoxmlSaveOptions(SaveFormat.Docx);
option.Compliance = OoxmlCompliance.Iso29500_2008_Transitional;
doc.Save(MyDir + "out.docx", option);

Thanks, works perfectly.

Hi Beat,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.