Xceed Words for .NET v4.0 Documentation
Replacing Text with HTML
Welcome to Xceed Words for .NET v4.0 > Code Snippets > Replacing Text with HTML

The following example demonstrates how to replace text with HTML in a Document.

The document contains tags that looks like <html_content>

These tags will be replaced by the HTML code that is read from an HTML document.

C#
Copy Code
static void Main( string[] args )
{
     // Load a document.
 using( var document = DocX.Load( "Template-2.docx" ) )
  {
   // Read HTML content.
   string html = File.ReadAllText( "HtmlSample.html" );
 
   // Create HtmlReplaceTextOptions Object in order to replace "<html_content>" tags with the HTML content that is read.
   var htmlReplaceTextOptions = new HtmlReplaceTextOptions()
    {
     SearchValue = "<html_content>",
     NewValue = html
    };
 
   // Replace all occurances of "<html_content>" in the document.
   document.ReplaceTextWithHTML( htmlReplaceTextOptions );
 
   // Save this document to disk.
   document.SaveAs( "ReplaceTextWithHtml.docx" );
  }
}