Replaces all matches of the textual string "textToReplace" in RTF file "rtfSourcePath" by the RTF string "wherewithReplaceRtf".

Namespace:  SautinSoft
Assembly:  SautinSoft.HtmlToRtf (in SautinSoft.HtmlToRtf.dll) Version: 7.1.4.17

Syntax

      
 C#  Visual Basic 
public int MergeAndReplaceRtfFileFromString(
	string sourcePath,
	string textToReplace,
	string wherewithReplaceRtf,
	string resultPath
)
Public Function MergeAndReplaceRtfFileFromString ( _
	sourcePath As String, _
	textToReplace As String, _
	wherewithReplaceRtf As String, _
	resultPath As String _
) As Integer

Parameters

sourcePath
String
A path to a RTF source file.
textToReplace
String
Textual string which will be replaced by the new string "wherewithReplaceInRtf"
wherewithReplaceRtf
String
String which will be inserted instead of "textToReplace"
resultPath
String
A path to a resulted RTF document. The file will be overwritten.

Return Value

0 - Replaced successfully.
1 - Can't open RTF source file.
3 - merging failed.
4 - can't create output file, check the output path.

Remarks

Creates a new RTF file. The file will be overwritten.



Examples

CopyReplace value in RTF document by another RTF using C#
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.MergeOptions.PageBreakBetweenDocuments = false;
            h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, textToReplace, wherewithReplaceRtfPath, resultRtfFile);

            // Show the result.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(resultRtfFile) { UseShellExecute = true });
        }
    }
}
CopyReplace value in RTF document by another RTF using VB.Net
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

See Also