This example demonstrates how to convert a RTF document to a Word document

Source RTF file:

We can use Rich text format word document data to convert into doc file

We see first file browser which is the primary rtf file whose content need to converted into another file format

Secondly, We have versions of this representation in words ,using dropdown you can make a choice within the following

  • Word Doc
  • Word Docx
  • Word ML
  • RTF
  • MS Text format
  • E-book format
  • DLS based xml file format
  • HTML

After clicking a generate button will launch a file with above choosen version of word , this file have content of selected rtf file.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Text;

using OfficeComponent.Word;

namespace OfficeComponent.Samples
    class RTFtoDOCExample : WordExampleBase
#if WEB
, IUIExample
        #region Inputs
        public string FilePath;

        public RTFtoDOCExample()
            : base(null,null)


        public RTFtoDOCExample(string commonDataPath, string outputDir)
            : base(commonDataPath, outputDir)


        public RTFtoDOCExample(string commonDataPath, string outputDir, string xmlFile) : base(commonDataPath, outputDir, xmlFile)


        public override string Execute()
#if WEB
            if (string.IsNullOrWhiteSpace(FilePath))
                ShowError("Please specify the file path.");
                return null;

            // Create a new instance of PdfDocument class.
            WordDocument document = new WordDocument();

            // Open the RTF document.
            document.Open(FilePath, WordDocumentFormat.Rtf);

            string fileName = Path.Combine(OutputDir, this.GetType().Name + "_" + Guid.NewGuid().ToString() + GetExtension(SaveAsFormat));
            // Save the document.
            document.Save(fileName, SaveAsFormat);

            // Close the document.

            return fileName;

        public override string ActionTitle
                return "Convert";

#if WEB
        void ProcessForm()
            FilePath = GetPostFile("SourceFile");
Imports System.Drawing.Imaging
Imports System.IO
Imports System.Text

Imports OfficeComponent.Word

Namespace OfficeComponent.Samples
#If WEB Then
	Friend Class RTFtoDOCExample
		Inherits WordExampleBase
		Implements IUIExample
	Friend Class RTFtoDOCExample
		Inherits WordExampleBase
#End If
		#Region "Inputs"
		Public FilePath As String
		#End Region

		Public Sub New()

		End Sub

		Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String)
			MyBase.New(commonDataPath, outputDir)

		End Sub

		Public Sub New(ByVal commonDataPath As String, ByVal outputDir As String, ByVal xmlFile As String)
			MyBase.New(commonDataPath, outputDir, xmlFile)

		End Sub

		Public Overrides Function Execute() As String
#If WEB Then
#End If
			If String.IsNullOrWhiteSpace(FilePath) Then
				ShowError("Please specify the file path.")
				Return Nothing
			End If

			' Create a new instance of PdfDocument class.
			Dim document As New WordDocument()

			' Open the RTF document.
			document.Open(FilePath, WordDocumentFormat.Rtf)

			Dim fileName As String = Path.Combine(OutputDir, Me.GetType().Name & "_" & Guid.NewGuid().ToString() & GetExtension(SaveAsFormat))
			' Save the document.
			document.Save(fileName, SaveAsFormat)

			' Close the document.

			Return fileName
		End Function

		Public Overrides ReadOnly Property ActionTitle() As String
				Return "Convert"
			End Get
		End Property

#If WEB Then
		Private Sub ProcessForm()
			FilePath = GetPostFile("SourceFile")
		End Sub
#End If
	End Class
End Namespace