Not able to edit content control in the particular document. When we edit , content is erased

Hi Team,

I am not able to edit the content control in the attached document. When edited , the content is erased. Is some property wrongly set.?

Auto-Tagged_BCG Agreement (4).docx (347.0 KB)

Please check.

@ashu_agrawal_sirionlabs_com

Cause

The issue you’re experiencing with the content control in your document is likely due to its configuration or the document’s protection settings. If the content control is locked or if the document has restrictions, attempting to edit it may result in the content being erased.

Solution

To resolve this, follow these steps:

  1. Content Control Properties: Ensure that the content control is not set to be read-only. Access the properties of the content control in your code to verify this.

  2. Document Protection: Check if the document is protected. If it is, you will need to remove the protection or adjust the permissions to allow editing.

  3. Using Aspose.Words: If you are using Aspose.Words, you can unlock the content control with the following code snippet:

Document doc = new Document("path/to/your/document.docx");
for (StructuredDocumentTag sdt : doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true)) {
    if (sdt.getTitle().equals("YourContentControlTitle")) {
        sdt.setLocked(false); // Unlock the content control
    }
}
doc.save("path/to/your/edited_document.docx");

Next Steps

  1. Check the properties of the content control in your document.
  2. Review any document protection settings that may be in place.
  3. Implement the provided code snippet to unlock the content control if necessary.

Please let me know if you need further assistance!

@ashu_agrawal_sirionlabs_com In your output document SDTs are marked with StructuredDocumentTag.IsShowingPlaceholderText . That is why text is not editable in the output document and is selected when you click on SDT. To prevent highlighting whole SDT content when it is clicked in MS Word, it is required to set StructuredDocumentTag.IsShowingPlaceholderText property to false .

Document doc = new Document("C:\\Temp\\in.docx");
        
for(StructuredDocumentTag tag : (Iterable<StructuredDocumentTag>)doc.getChildNodes(NodeType.STRUCTURED_DOCUMENT_TAG, true))
    tag.isShowingPlaceholderText(false);
        
doc.save("C:\\Temp\\out.docx");