Replaces all matches of string "whatReplaceInRtf" in RTF file "rtfSourcePath" by the content of file "wherewithReplaceRtfPath".

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

Syntax

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

Parameters

sourcePath
String
Path to source RTF file
textToReplace
String
Textual string which will be replaced by the new string "wherewithReplaceInRtf"
wherewithReplaceRtfPath
String
Path to RTF file which will be inserted into source RTF
resultPath
String
Path to new merged RTF file. A fill will be overwritten

Return Value

0 - merged successfully
1 - can't open RTF source file
2 - can't open 'wherewithReplaceRtfPath' file
3 - merging failed
4 - can't create output file, check the output path

Remarks

Creates a new RTF file "resultPath"



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