If cbOkHagana.Checked = True Then
WordApplication.Selection.Editors.Add(Microsoft.Office.Interop.Word.WdEditorType.wdEditorEveryone)
WordApplication.ActiveDocument.Protect(Microsoft.Office.Interop.Word.WdProtectionType.wdAllowOnlyReading, False, "11111", False, False)
MessageBox.Show("הפעלת ההגנה עברה בהצלחה ")
End If
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.
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).
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.
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);
AsposeDocument.Protect(ProtectionType.ReadOnly);
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.
AsposeDocument.Sections[intprotect].ReadOnly = false;
}
We need a rapid solution for this problem ( our project in production).
We also need a solution for printing with viewer .
I remind you that you promis solution for this problems in 2007.
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).
Thank you for additional information. I think that as workaround you can use MergeFields instead FormFields and then use AllowonlyFormFelds protection type.
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 :
I have a word document with protected and unprotected sections ( one or more) defined by Word.
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.
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.
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);
}
}
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;
}
}
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.