How to replace value in RTF document by another RTF
in C# and VB.Net.


Complete code.

using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // How to replace values in RTF document by another RTF content.
            // If you need more information about "HTML to RTF .Net" email us at:
            // support@sautinsoft.com	
            ReplaceValuesInRtf();
        }

        public static void ReplaceValuesInRtf()
        {
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();

            // After purchasing the license, please insert your serial number here to activate the component.
            // h.Serial = "XXXXXXXXX";

            // For example, we've RTF with such content "This is a sample footer as RTF document."
            // Let's replace the string "sample" by another RTF file.
            string sourceRtfFile = @"..\..\footer.rtf";
            string wherewithReplaceRtfPath = @"..\..\footer.rtf";
            string textToReplace = "sample";
            string resultRtfFile = Path.ChangeExtension(sourceRtfFile, ".result.rtf");

            h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, textToReplace, wherewithReplaceRtfPath, resultRtfFile);

            // Show the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultRtfFile) { UseShellExecute = true });
        }
    }
}

Download.

        
            Imports System
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        ' How to replace values in RTF document by another RTF content.
        ' If you need more information about "HTML to RTF .Net" email us at:
        ' support[at]sautinsoft.com	
        ReplaceValuesInRtf()
    End Sub

    Public Sub ReplaceValuesInRtf()
        Dim h As New SautinSoft.HtmlToRtf()

        ' After purchasing the license, please insert your serial number here to activate the component.
        'h.Serial = "XXXXXXXXX"

        ' For example, we've RTF with such content "This is a sample footer as RTF document."
        ' Let's replace the string "sample" by another RTF file.
        Dim sourceRtfFile As String = "..\footer.rtf"
        Dim wherewithReplaceRtfPath As String = "..\footer.rtf"
        Dim textToReplace As String = "sample"
        Dim resultRtfFile As String = Path.ChangeExtension(sourceRtfFile, ".result.rtf")

        h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, textToReplace, wherewithReplaceRtfPath, resultRtfFile)

        ' Show the result.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(resultRtfFile) With {.UseShellExecute = True})
    End Sub
End Module

Download.


If you need a new code example or have a question: email us at support@sautinsoft.com or ask at Online Chat (right-bottom corner of this page) or use the Form below:



Questions and suggestions from you are always welcome!

We are developing .Net components since 2002. We know PDF, DOCX, RTF, HTML, XLSX and Images formats. If you need any assistance with creating, modifying or converting documents in various formats, we can help you. We will write any code example for you absolutely free.