Click or drag to resize

RtfLoadOptions Class

Represents a class that stores loading options for Rich Text (RTF) format.
Inheritance Hierarchy

Namespace:  SautinSoft.Document
Assembly:  SautinSoft.Document (in SautinSoft.Document.dll) Version: 4.0.10.28 (4.0.10.28)
Syntax
public sealed class RtfLoadOptions : LoadOptions

The RtfLoadOptions type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleRtfLoadOptions
Initializes a new instance of the RtfLoadOptions class.
Top
Properties
  NameDescription
Public propertyEncoding
Gets or sets the encoding for the RTF file.
Public propertyPreserveUnsupportedFeatures
Gets or sets a value indicating whether to preserve file format features that are not directly supported.
(Inherited from LoadOptions.)
Top
Methods
  NameDescription
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)
Top
Examples
How to load a RTF document using C#
using System;
using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {

        static void Main(string[] args)
        {
            //LoadRtfFromStream();
            LoadRtfFromFile();
        }

        /// <summary>
        /// Loads an RTF document into DocumentCore (dc) from a file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/load-rtf-document-net-csharp-vb.php
        /// </remarks>
        static void LoadRtfFromFile()
        {
            string filePath = @"..\..\example.rtf";

            // The file format is detected automatically from the file extension: ".rtf".
            // But as shown in the example below, we can specify RtfLoadOptions as 2nd parameter
            // to explicitly set that a loadable document has RTF format.
            DocumentCore dc = DocumentCore.Load(filePath);

            if (dc != null)
                Console.WriteLine("Loaded successfully!");

            Console.ReadKey();            
        }

        /// <summary>
        /// Loads an RTF document into DocumentCore (dc) from a file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/load-rtf-document-net-csharp-vb.php
        /// </remarks>
        static void LoadRtfFromStream()
        {
            // Get document bytes.
            byte[] fileBytes = File.ReadAllBytes(@"..\..\example.rtf");

            DocumentCore dc = null;

            // Create a MemoryStream
            using (MemoryStream ms = new MemoryStream(fileBytes))
            {
                // Load a document from the MemoryStream.
                // Specifying RtfLoadOptions we explicitly set that a loadable document is RTF.
                dc = DocumentCore.Load(ms, new RtfLoadOptions());
            }
            if (dc != null)
                Console.WriteLine("Loaded successfully!");

            Console.ReadKey();            
        }
    }
}
How to load a RTF document using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        'LoadRtfFromStream();
        LoadRtfFromFile()
    End Sub

    ''' <summary>
    ''' Loads an RTF document into DocumentCore (dc) from a file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-rtf-document-net-csharp-vb.php
    ''' </remarks>
    Sub LoadRtfFromFile()
        Dim filePath As String = "..\example.rtf"

        ' The file format is detected automatically from the file extension: ".rtf".
        ' But as shown in the example below, we can specify RtfLoadOptions as 2nd parameter
        ' to explicitly set that a loadable document has RTF format.
        Dim dc As DocumentCore = DocumentCore.Load(filePath)

        If dc IsNot Nothing Then
            Console.WriteLine("Loaded successfully!")
        End If

        Console.ReadKey()        
    End Sub

    ''' <summary>
    ''' Loads an RTF document into DocumentCore (dc) from a file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-rtf-document-net-csharp-vb.php
    ''' </remarks>
    Sub LoadRtfFromStream()
        ' Get document bytes.
        Dim fileBytes() As Byte = File.ReadAllBytes("..\example.rtf")

        Dim dc As DocumentCore = Nothing

        ' Create a MemoryStream
        Using ms As New MemoryStream(fileBytes)
            ' Load a document from the MemoryStream.
            ' Specifying RtfLoadOptions we explicitly set that a loadable document is RTF.
            dc = DocumentCore.Load(ms, New RtfLoadOptions())
        End Using
        If dc IsNot Nothing Then
            Console.WriteLine("Loaded successfully!")
        End If

        Console.ReadKey()        
    End Sub

End Module
See Also