How to protect entire word document except ribbon and content control text by Aspose C#

TestDocument.zip (15.9 KB)

Hi,
My requirement is to protect the entire word document , but content controls in word document should be enabled for editing and document ribbon should be enabled . So user can edit content control text by applying styles selecting from ribbon . I can do the same by using Microsoft.Office.Interop.Word . I want to do the same using Aspose .
Attached sample word document where there are 2 content controls and some text inside and outside of content controls . I need to protect outside text so user can not edit them and enable content control so user can edit inside text , but document ribbon should be enabled
Please let me know how it is possible in Aspose c#
Thanks

@rasmi.mishra

Thanks for your inquiry. You can mark whole document as read-only and specify editable regions in Word document. Please use the following code to get desired results.

Document doc = new Document("D:\\Temp\\TestDocument.docx");
doc.Protect(ProtectionType.ReadOnly);

NodeCollection sdtCollections = doc.GetChildNodes(NodeType.StructuredDocumentTag, true);
DocumentBuilder builder = new DocumentBuilder(doc);


foreach(CompositeNode sdt in sdtCollections) {    
 EditableRangeStart start = builder.StartEditableRange();
 EditableRangeEnd end = builder.EndEditableRange();

 int totalChildrens = sdt.GetChildNodes(NodeType.Run, true).Count;
 int i = 1;
 foreach(Node child in sdt.GetChildNodes(NodeType.Run, true)) {

  if (child.NodeType.Equals(NodeType.Run)) {

   Run run = (Run) child;
   if (totalChildrens == 1) {
    run.ParentNode.InsertBefore(start, run);
    run.ParentNode.InsertAfter(end, run);
   } else {
    if (i == 1) {
     run.ParentNode.InsertBefore(start, run);
    } else if (i == totalChildrens) {
     run.ParentNode.InsertAfter(end, run);
    }
   }
  }
  i++;
 }
}

doc.Save("D:\\Temp\\TestDocument_18.12.docx");

Hope, this helps.

Please check attached document for your reference. TestDocument_18.12.zip (10.9 KB)

Hi @mannanfazil
Thanks for your response , is it possible to enable the track change button(including Accept and Reject button ) in your attached document where document is protected and only content controls are editable
Please let me know , thanks

@rasmi.mishra

You can use Document.TrackRevisions property to instruct Microsoft Word whether the track changes is turned on or off. This property has no effect on changes to the document that you make programmatically via Aspose.Words.

If you still face problem, please ZIP and attach your input and expected output documents here for our reference. We will then provide you more information about your query.