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
#endif
{
#region Inputs
public string FilePath;
#endregion
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
ProcessForm();
#endif
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.
document.Close();
return fileName;
}
public override string ActionTitle
{
get
{
return "Convert";
}
}
#if WEB
void ProcessForm()
{
FilePath = GetPostFile("SourceFile");
}
#endif
}
}
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
#Else
Friend Class RTFtoDOCExample
Inherits WordExampleBase
#End If
#Region "Inputs"
Public FilePath As String
#End Region
Public Sub New()
MyBase.New(Nothing,Nothing)
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
ProcessForm()
#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.
document.Close()
Return fileName
End Function
Public Overrides ReadOnly Property ActionTitle() As String
Get
Return "Convert"
End Get
End Property
#If WEB Then
Private Sub ProcessForm()
FilePath = GetPostFile("SourceFile")
End Sub
#End If
End Class
End Namespace