Click or drag to resize

DocxLoadOptions Class

Represents a class that stores loading options for Microsoft Word (DOCX) format.
Inheritance Hierarchy

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

The DocxLoadOptions type exposes the following members.

Constructors
  NameDescription
Public methodCode exampleDocxLoadOptions
Initializes a new instance of the DocxLoadOptions class.
Top
Properties
  NameDescription
Public propertyEmbedExternalImages
Gets or sets a value indicating whether external images should be embedded directly into document.
Public propertyPassword
Gets or sets the password to open protected / encrypted document.
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 DOCX document in C#
using System;
using System.IO;
using SautinSoft.Document;

namespace Example
{
    class Program
    {      
        static void Main(string[] args)
        {
            LoadDocxFromFile();
            //LoadDocxFromStream();
        }

        /// <summary>
        /// Loads a DOCX document into DocumentCore (dc) from a file.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/load-docx-document-net-csharp-vb.php
        /// </remarks>
        static void LoadDocxFromFile()
        {
            string filePath = @"..\..\example.docx";
            // The file format is detected automatically from the file extension: ".docx".
            // But as shown in the example below, we can specify DocxLoadOptions as 2nd parameter
            // to explicitly set that a loadable document has Docx format.
            DocumentCore dc = DocumentCore.Load(filePath);

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

            Console.ReadKey();
        }

        /// <summary>
        /// Loads a DOCX document into DocumentCore (dc) from a MemoryStream.
        /// </summary>
        /// <remarks>
        /// Details: https://www.sautinsoft.com/products/document/examples/load-docx-document-net-csharp-vb.php
        /// </remarks>
        static void LoadDocxFromStream()
        {
            // Assume that we already have a DOCX document as bytes array.
            byte[] fileBytes = File.ReadAllBytes(@"..\..\example.docx");

            DocumentCore dc = null;

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

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

Module Sample
    Sub Main()
        LoadDocxFromFile()
        'LoadDocxFromStream();
    End Sub

    ''' <summary>
    ''' Loads a DOCX document into DocumentCore (dc) from a file.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-docx-document-net-csharp-vb.php
    ''' </remarks>
    Sub LoadDocxFromFile()
        Dim filePath As String = "..\example.docx"
        ' The file format is detected automatically from the file extension: ".docx".
        ' But as shown in the example below, we can specify DocxLoadOptions as 2nd parameter
        ' to explicitly set that a loadable document has Docx 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 a DOCX document into DocumentCore (dc) from a MemoryStream.
    ''' </summary>
    ''' <remarks>
    ''' Details: https://www.sautinsoft.com/products/document/examples/load-docx-document-net-csharp-vb.php
    ''' </remarks>
    Sub LoadDocxFromStream()
        ' Assume that we already have a DOCX document as bytes array.
        Dim fileBytes() As Byte = File.ReadAllBytes("..\example.docx")

        Dim dc As DocumentCore = Nothing

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

        Console.ReadKey()        
    End Sub
End Module
See Also