Converts Text/RTF/DOCX file to Text/HTML/XHTML file. Output file will be overwritten.

Namespace:  SautinSoft
Assembly:  SautinSoft.RtfToHtml (in SautinSoft.RtfToHtml.dll) Version: 6.2.2.1

Syntax

      
 C#  Visual Basic 
public int ConvertFile(
	string inputFileName,
	string outputFileName
)
Public Function ConvertFile ( _
	inputFileName As String, _
	outputFileName As String _
) As Integer

Parameters

inputFileName
String
Path to Text/RTF/DOCX file, not URL
outputFileName
String
Path to output file

Return Value

0 - converting succesfully
1 - can't open an input file, check the input path
2 - can't create output file, check the output path
3 - converting failed

Remarks

Examples

CopyHow to convert RTF file into HTML file in C#
using System;
using System.IO;
using System.Text;

namespace SampleConvert
{
    class sample
    {
        static void Main(string[] args)
        {
            SautinSoft.RtfToHtml r = new SautinSoft.RtfToHtml();
            string AppPath=System.Environment.CurrentDirectory;

            //specify some options
            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5;
            r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8;

            //specify image options
            r.ImageStyle.ImageFolder = AppPath;            //this folder must exist
            r.ImageStyle.ImageSubFolder = "test.files";    //this folder will be created by the component
            r.ImageStyle.ImageFileName = "img";            //template name for images
            r.ImageStyle.IncludeImageInHtml = false;    //false - save images on HDD, true - save images inside HTML            

            string rtfFile = Path.GetFullPath(@"..\..\..\..\..\test.rtf");
            string htmlFile = Path.Combine(AppPath,"test.html"); //the result will be located in the same folder as binary

            int i = r.ConvertFile(rtfFile,htmlFile);
            if (i == 0)
            {
                System.Console.WriteLine("Converted successfully!");
                System.Diagnostics.Process.Start(htmlFile);
            }
            else
            {
                System.Console.WriteLine("Conversion failed!");
                Console.ReadLine();
            }
        }
    }
}
CopyHow to convert RTF file into HTML file in VB.Net
Imports System.IO
Imports System.Text

Namespace SampleConvert
    Friend Class sample
        Shared Sub Main(ByVal args() As String)
            Dim r As New SautinSoft.RtfToHtml()
            Dim AppPath As String = System.Environment.CurrentDirectory

            'specify some options
            r.OutputFormat = SautinSoft.RtfToHtml.eOutputFormat.HTML_5
            r.Encoding = SautinSoft.RtfToHtml.eEncoding.UTF_8

            'specify image options
            r.ImageStyle.ImageFolder = AppPath 'this folder must exist
            r.ImageStyle.ImageSubFolder = "test.files" 'this folder will be created by the component
            r.ImageStyle.ImageFileName = "img" 'template name for images
            r.ImageStyle.IncludeImageInHtml = False 'false - save images on HDD, true - save images inside HTML



            Dim rtfFile As String = Path.GetFullPath("..\..\..\..\..\test.rtf")
            Dim htmlFile As String = Path.Combine(AppPath, "test.html") 'the result will be located in the same folder as binary


            Dim i As Integer = r.ConvertFile(rtfFile, htmlFile)
            If i = 0 Then
                System.Console.WriteLine("Converted successfully!")
                System.Diagnostics.Process.Start(htmlFile)
            Else
                System.Console.WriteLine("Conversion failed!")
                Console.ReadLine()
            End If
        End Sub
    End Class
End Namespace

See Also