Merge two RTF files and create new sinlge RTF document. Output file will be overwritten.

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

Syntax

      
 C#  Visual Basic 
public int MergeRtfFile(
	string rtfFilePath1,
	string rtfFilePath2,
	string singleMergedRtf
)
Public Function MergeRtfFile ( _
	rtfFilePath1 As String, _
	rtfFilePath2 As String, _
	singleMergedRtf As String _
) As Integer

Parameters

rtfFilePath1
String
Path to 1st RTF document
rtfFilePath2
String
Path to 2nd RTF document
singleMergedRtf
String
Local path to save output RTF

Return Value

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

Remarks

A merged RTF document will contain 1st RTF document and next 2nd RTF document by order.



Examples

CopyHow to merge two RTF files in C#
using System;
using System.IO;

namespace Sample
{
    class Test
    {

        static void Main(string[] args)
        {
            // Merge two RTF documents in memory
            // 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");

            string rtf1 = File.ReadAllText(Path.Combine(htmlDir.FullName, "footer.rtf"));
            string rtf2 = File.ReadAllText(Path.Combine(htmlDir.FullName, "footer.rtf"));

            string rtfSingle = h.MergeRtfString(rtf1, rtf2);

            // Save 'rtfString' to a file for demonstration purposes.
            if (!String.IsNullOrEmpty(rtfSingle))
            {
                string singleRtfFile = Path.Combine(htmlDir.FullName, "single.rtf");
                File.WriteAllText(singleRtfFile, rtfSingle);
                System.Diagnostics.Process.Start(singleRtfFile);
            }
        }
    }
}
CopyHow to merge two RTF files in VB.Net
Imports System
Imports System.IO
Imports System.Text

Module Module1
    Sub Main()
        ' Merge two RTF documents in memory
        ' 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")

        Dim rtf1 As String = File.ReadAllText(Path.Combine(htmlDir.FullName, "footer.rtf"))
        Dim rtf2 As String = File.ReadAllText(Path.Combine(htmlDir.FullName, "footer.rtf"))

        Dim rtfSingle As String = h.MergeRtfString(rtf1, rtf2)

        ' Save 'rtfString' to a file for demonstration purposes.
        If Not String.IsNullOrEmpty(rtfSingle) Then
            Dim singleRtfFile As String = Path.Combine(htmlDir.FullName, "single.rtf")
            File.WriteAllText(singleRtfFile, rtfSingle)
            System.Diagnostics.Process.Start(singleRtfFile)
        End If
    End Sub
End Module

See Also