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

Free Support Forum - aspose.com

Aspose.Words .Net - Custom Controls

In the Asp.net application, have to generate a word document from a template (Attached document MemberLetter.docx).

The template has static content as well as content controls.The values of Content Control are dynamic and would change. How do I code to populate the content controls with values using Aspose.Words.

I tried this:

Document doc = new Document(@“C:\AsposeConentControl\Docs\MemberLetter.docx”);
foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))
{
if (sdt.Tag == “Name”)
{

<…>
}
}
I did not get any method to set the text of the content control.
sdt.GetText gets the text of the content control by the the tag but how to set the text for the control.

Please could you provide sample code for this.

Thanks.

Hi Aparna,


Thanks for your inquiry. Please try executing the following code to achieve this:

Document doc = new Document(MyDir + @“MemberLetter.docx”);

foreach (StructuredDocumentTag sdt in doc.GetChildNodes(NodeType.StructuredDocumentTag, true))

{

Console.WriteLine(sdt.Tag);

if (sdt.Tag == "Name")

{

sdt.RemoveAllChildren();

Run someText = new Run(doc, "SOME TEXT");

sdt.AppendChild(someText);

sdt.IsShowingPlaceholderText = false;

}

}

doc.Save(MyDir + @“out.docx”);


I hope, this helps.

Best regards,