DocumentCore dc = DocumentCore.Load(@"d:\Book.rtf");
Объект dc представляет собой документ "Book.rtf", загруженный в память. Формат файла определяется автоматически по расширению файла: ".rtf".
После загрузки Вы получите документ, представленный в виде Tree Of Objects, где корневым узлом является класс DocumentCore.
Чтобы гарантировать, что загружаемый контент действительно является RTF, и установить некоторые параметры загрузки, используйте RtfLoadOptions в качестве второго параметра.
DocumentCore dc = DocumentCore.Load(@"d:\Book.rtf", new RtfLoadOptions());
// Let us say we already have a RTF document as array of bytes.
DocumentCore dc = null;
using (MemoryStream rtfStream = new MemoryStream(rtfBytes))
{
dc = DocumentCore.Load(rtfStream, new RtfLoadOptions());
}
// Here we can do with our document 'dc' anything we need.
Полный код
using System;
using System.IO;
using SautinSoft.Document;
namespace Example
{
class Program
{
static void Main(string[] args)
{
// Get your free 100-day key here:
// https://sautinsoft.com/start-for-free/
//LoadRtfFromStream();
LoadRtfFromFile();
}
/// <summary>
/// Loads an RTF document into DocumentCore (dc) from a file.
/// </summary>
/// <remarks>
/// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/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/help/net/developer-guide/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();
}
}
}
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
Sub Main()
'LoadRtfFromStream();
LoadRtfFromFile()
End Sub
''' Get your free 100-day key here:
''' https://sautinsoft.com/start-for-free/
''' <summary>
''' Loads an RTF document into DocumentCore (dc) from a file.
''' </summary>
''' <remarks>
''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/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/help/net/developer-guide/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
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу support@sautinsoft.com или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: