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

# Protect and Unprotect

I can to protect my file in Word.

How can i do this in Aspose.Words?

If cbOkHagana.Checked = True Then
MessageBox.Show("הפעלת ההגנה עברה בהצלחה ")
End If


Hi,

Thank you for your request. This is even more straightforward when using Aspose.Words:

Document doc = new Document("MyDocument.doc");


To know more, please read the following article of the product’s documentation:
https://docs.aspose.com/words/net/protect-or-encrypt-a-document/

I have two or more unprotected and protected sections in Word document. I open Word document with Aspose.Words and working with this document. I must Unprotect a whole document and after working protected only sections which had been protected in original Word document.

Thanks

Hi,

Thank you for your request. It seems that it is bug. After opening/saving this document using Aspose.Words this document became ReadOnly. I created an issue # 3936 in our defects database. Please expect a reply before the next hotfix (within 2-3 weeks).

Best regards.

I see the release notes , but you don’t resolve at issue #3936.

I must resolve thise problem in our production and this must be done without delay.

You have another solution?

Thank’s

Hi

Unfortunately, this issue is still unresolved. This issue has the Show Stopper priority in our defect’s database.

As workaround you can try to use FormFields and protection type AllowOnlyFormFields. See the following link.
https://apireference.aspose.com/words/net/aspose.words/protectiontype

Best regards.

Hi!

We must resolve this problem for our production.

We must protect just the protected section and unprotect unprotected section ( How Word to do this!).

For us this problem in Aspose.Word is in High priority.

Sorry, for the delay.

Your document contains an “editable region”. Editable regions are not supported by Aspose.Words yet.

You can set a protection for the whole document or for a section. Section means “MS Word section”, that is a portion of the document delimeted by section breaks.

See https://apireference.aspose.com/words/net/aspose.words/protectiontype for an example.

Also see https://docs.aspose.com/words/net/protect-or-encrypt-a-document/ for general info about document protection.

Editable regions will be supported in Aspose.Words in the future, sometime in 2008.

Hi!

For our production we need a solution for “Editable range” ( I wrote this).

This code don’t work (we must read only !) and how I can see that section is protected or not? (strProtectionType = AsposeDocument.Sections[intprotect].ProtectionType; this is not working! ):

Aspose.Words.Sections sectionProtected = AsposeDocument.Sections;
WriteToTextLog("Aspose Protect", 1);
WriteToTextLog("Aspose Protect section number :" + sectionProtected.Count, 1);
for (int intprotect = 1; intprotect < sectionProtected.Count; intprotect += 2)
{
// By default, all sections are protected, but we can selectively turn protection off.
}

1. We need a rapid solution for this problem ( our project in production).

2. We also need a solution for printing with viewer .

I remind you that you promis solution for this problems in 2007.

Thank’s

Isabel

Hi

Thanks for your request. I think that you can try using AllowonlyFormFelds protection type. For example see the following code and attached documents.

Document doc = new Document(@"Test010\in.doc");
doc.Protect(ProtectionType.AllowOnlyFormFields);
doc.Sections[1].ProtectedForForms = false;
doc.Save(@"Test010\out.doc");


https://apireference.aspose.com/words/net/aspose.words/section/properties/protectedforforms

Hope this helps.

Best regards.

Hi!

I wrote that we must ReadOnly. (See my code example).It is impossible in our project change the text after merge in formfields .It can be changed just in editeble range (section).

Hi!

I attach a sample file . After merge data on to formfields , just the three sections is editable ( in yellow ) the other sections is read only.

How I do this with your solution? My code example i wrote in previous message.

Thenk you for you helping.

Isabel

Hi

Thank you for additional information. I think that as workaround you can use MergeFields instead FormFields and then use AllowonlyFormFelds protection type.

Best regards.

Hi!

You don’t undestand. This is a problem , not information. Aspose.Words don’t see this sections! (editable sections from Word! - marked by yellow collor). You see this file on previous message.

I must resolve this problem :

1. I have a word document with protected and unprotected sections ( one or more) defined by Word.

2. I open this document with Aspose.Words. I must see this sections , merge formfield with data and protect just the sections that was protected early.

How can do this with attached document?

Thank’s

Isabel

Hi

There is only one section in your document. Editable regions (marked by yellow color) are not section. As we told you earlier, editable regions are not supported by Aspose.Words. That’s why your output document is ReadOnly protected.

https://docs.aspose.com/words/net/working-with-sections/

Best regards.

Hi!

I try to use with Sections from your proposition. But our formfields are not protected after appleing ptotected sections ( even sections 0 ,2,4…) and unprotected sections.May i remove ( clear) the definition of formfield after merge the text into formfield ? ( but not a result text !).

I attach , my file after merge and protected just even sections. But this protect just the text .

This is

private void DocumentProtect()
{
Aspose.Words.Sections sectionProtected = AsposeDocument.Sections;
int intSections = 0;
try
{
WriteToEventLog("Protect With Aspose With" + sectionProtected.Count + "Sections", 2);
WriteToTextLog("Protect With Aspose With" + sectionProtected.Count + "Sections", 2);
AsposeDocument.Protect(ProtectionType.AllowOnlyFormFields, strProtection);
for (intSections = 1; intSections < sectionProtected.Count; intSections += 2)
{
AsposeDocument.Sections[intSections].ProtectedForForms = false;
WriteToTextLog("Protect With Aspose Section number " + intSections + " unprotected", 2);
}
}
catch (Exception err)
{
objUserDefinedObject.msg.rcMessage = err.Message;
objUserDefinedObject.msg.rcType = (int)msg.rcTypes.Error;
objUserDefinedObject.msg.rcNumber = 16;
WriteToTextLog("Error on insert data to field because protection: " + err.Message, 1);
WriteToEventLog("Error on insert data ti fields because protection: " + err.Message, 1);
}
}


Thank 's

Hi

Thanks for your inquiry. I think that you can try using Bookmarks instead FormFields. To set text of bookmark you can use the following code.

doc.Range.Bookmarks["myBookmark"].Text = "test";


Best regards.

Hi!

This is don’t help me. I using formfield , I send my code for examle :

I must clear all formfield after merge , like that protect (or unprotect ) in section see just text ( result) .And protected (or unprotected) as if the text.

Aspose.Words.FormField formField2 = documentFormFields[bookname];
if (formField2.Type == Aspose.Words.FieldType.FieldFormCheckBox)
{
if (text == "true")
{
formField2.Checked = true;
}
else
{
formField2.Checked = false;
}
}//if (formField2.Type == Aspose.Words.FieldType.FieldFormCheckBox)
else
{
switch (strTypeData)
{
case "0":
formField2.Result = text.Trim();
break;
case "2":
text = UpdateDate(text);
formField2.Result = text;
break;
case "3":
formField2.Result = text.Trim();
break;
case "4":
text = UpdateTime(text);
formField2.Result = text;
break;
default:
formField2.Result = text.Trim();
break;
}
}


Thank’s

Hi

As I told you there is no way to fully protect or unprotect a region of a document. One way to do this is using AllowOnlyFormFields and separate sections as you do in your document. But if you use AllowOnlyFormFields protecting type then all FormField will be editable. I think as a workaround you can use bookmarks or Mail Merge to fill your template with data. Please tell me if you have any other ideas how you can do this and I will try to help you.

Best regards.

Hi!

I change formfield to mergfield and i use with sections as you advise.

Now the problem with mergefield in table. How I Know that mergfield belong (instead in cell) to table. Perhaps more than one table in the file.

In our logic I take name of mergefield ( in the past formfield) and by name I search Tags in XML file.

I must clone the rows in table by quantity of Tags With name of mergefield in XML file.

I attach word file for example and XML file.

Thank’s