Click or drag to resize

TxtSaveOptions Class

Represents options for saving to plain text (TXT) format.
Inheritance Hierarchy
SystemObject
  SautinSoft.DocumentSaveOptions
    SautinSoft.DocumentTxtSaveOptions

Namespace: SautinSoft.Document
Assembly: SautinSoft.Document (in SautinSoft.Document.dll) Version: 2024.11.20
Syntax
public sealed class TxtSaveOptions : SaveOptions

The TxtSaveOptions type exposes the following members.

Constructors
 NameDescription
Public methodCode exampleTxtSaveOptions Initializes a new instance of the TxtSaveOptions class.
Top
Properties
 NameDescription
Public propertyContentType Gets the content-type for TXT file format: "text/plain; charset=" + WebName.
(Overrides SaveOptionsContentType)
Public propertyEncoding Gets or sets the encoding for the TXT file. Default value is UTF8.
Public propertyLineBreak Gets or sets the string to use as a line break. Default value: NewLine.
Public propertyParagraphBreak Gets or sets the string to use as a paragraph break. Default value: NewLine.
Public propertyTableCellDelimiter Gets or sets the string to use as a table cell delimiter. Default value is Tab.
Public propertyTableRowDelimiter Gets or sets the string to use as a table cell delimiter. Default value is NewLine.
Top
Example

See Developer Guide: How to save a document in Text format

How to save a document in Text format using C#
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/

            SaveToTextFile();
            SaveToTextStream();
        }

        /// <summary>
        /// Creates a new document and saves it as Text file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-text-net-csharp-vb.php
        /// </remarks>
        static void SaveToTextFile()
        {
            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey Guys and Girls!");

            string filePath = @"Result-file.txt";

            dc.Save(filePath, new TxtSaveOptions()
            {
                Encoding = System.Text.Encoding.UTF8,
                ParagraphBreak = Environment.NewLine
            });

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }

        /// <summary>
        /// Creates a new document and saves it as Text using MemoryStream.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-text-net-csharp-vb.php
        /// </remarks>
        static void SaveToTextStream()
        {
            // There variables are necessary only for demonstration purposes.
            byte[] fileData = null;
            string filePath = @"Result-stream.txt";

            // Assume we already have a document 'dc'.
            DocumentCore dc = new DocumentCore();
            dc.Content.End.Insert("Hey Guys and Girls!");

            // Let's save our document to a MemoryStream.
            using (MemoryStream ms = new MemoryStream())
            {
                dc.Save(ms, new TxtSaveOptions());
                fileData = ms.ToArray();
            }
            File.WriteAllBytes(filePath, fileData);

            // Important for Linux: Install MS Fonts
            // sudo apt install ttf-mscorefonts-installer -y

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(filePath) { UseShellExecute = true });
        }
    }
}
How to save a document in Text format using VB.Net
Imports System
Imports System.IO
Imports SautinSoft.Document

Module Sample
    Sub Main()
        SaveToTextFile()
        SaveToTextStream()
    End Sub
    ''' Get your free 100-day key here:   
    ''' https://sautinsoft.com/start-for-free/
    ''' <summary>
    ''' Creates a new document and saves it as Text file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-text-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToTextFile()
        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey Guys and Girls!")

        Dim filePath As String = "Result-file.txt"

        dc.Save(filePath, New TxtSaveOptions() With {
            .Encoding = System.Text.Encoding.UTF8,
            .ParagraphBreak = Environment.NewLine
        })

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub

    ''' <summary>
    ''' Creates a new document and saves it as Text using MemoryStream.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/help/net/developer-guide/save-document-as-text-net-csharp-vb.php
    ''' </remarks>
    Sub SaveToTextStream()
        ' There variables are necessary only for demonstration purposes.
        Dim fileData() As Byte = Nothing
        Dim filePath As String = "Result-stream.txt"

        ' Assume we already have a document 'dc'.
        Dim dc As New DocumentCore()
        dc.Content.End.Insert("Hey Guys and Girls!")

        ' Let's save our document to a MemoryStream.
        Using ms As New MemoryStream()
            dc.Save(ms, New TxtSaveOptions())
            fileData = ms.ToArray()
        End Using
        File.WriteAllBytes(filePath, fileData)

        ' Open the result for demonstration purposes.
        System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(filePath) With {.UseShellExecute = True})
    End Sub
End Module
See Also