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: 5.8.2.8

Syntax

      
 C#  Visual Basic 
public int MergeAndReplaceRtfFileFromFile(
	string rtfSourcePath,
	string whatReplaceInRtf,
	string wherewithReplaceRtfPath,
	string newMergedRtfPath
)
Public Function MergeAndReplaceRtfFileFromFile ( _
	rtfSourcePath As String, _
	whatReplaceInRtf As String, _
	wherewithReplaceRtfPath As String, _
	newMergedRtfPath As String _
) As Integer

Parameters

rtfSourcePath
String
Path to source RTF file
whatReplaceInRtf
String
String which will be replaced
wherewithReplaceRtfPath
String
Path to RTF file which will be inserted into source RTF
newMergedRtfPath
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 "newMergedRtfPath"



Examples

CopyInsert one RTF file inside another RTF file in C#
using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Replace values in RTF document
            // If you need more information about "HTML to RTF .Net" email us at:
            // support[at]sautinsoft.com        
            SautinSoft.HtmlToRtf h = new SautinSoft.HtmlToRtf();
            // After purchasing the license, please insert your serial number here to activate the component
            //h.Serial = "XXXXXXXXXXXXXXX";

            DirectoryInfo htmlDir = new DirectoryInfo(@"..\..\..\..\..\..\Testing HTMLs");

            // 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 = Path.Combine(htmlDir.FullName, "footer.rtf");
            string replacingRtfFile = Path.Combine(htmlDir.FullName, "footer.rtf");
            string whatReplace = "sample";
            string resultRtfFile = Path.Combine(htmlDir.FullName, "result.rtf");

            h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, whatReplace, replacingRtfFile, resultRtfFile);

            // Show produced result.
            System.Diagnostics.Process.Start(resultRtfFile);
        }
    }
}
CopyInsert one RTF file inside another RTF file in VB.Net
Imports System
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        ' Replace values in RTF document
        ' If you need more information about "HTML to RTF .Net" email us at:
        ' support[at]sautinsoft.com        
        Dim h As New SautinSoft.HtmlToRtf()
        ' After purchasing the license, please insert your serial number here to activate the component
        'h.Serial = "XXXXXXXXXXXXXXX";


        Dim htmlDir As New DirectoryInfo("..\..\..\..\..\Testing HTMLs")

        ' 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 = Path.Combine(htmlDir.FullName, "footer.rtf")
        Dim replacingRtfFile As String = Path.Combine(htmlDir.FullName, "footer.rtf")
        Dim whatReplace As String = "sample"
        Dim resultRtfFile As String = Path.Combine(htmlDir.FullName, "result.rtf")

        h.MergeAndReplaceRtfFileFromFile(sourceRtfFile, whatReplace, replacingRtfFile, resultRtfFile)

        ' Show produced result.
        System.Diagnostics.Process.Start(resultRtfFile)
    End Sub
End Module

See Also