---
title: "Specify Load Options in C#"
---


{{% alert color="grey" %}}

## Purpose Summary

This page explains how to specify load options when opening a document.

{{% /alert %}}

When loading a document, you can set some advanced properties. Aspose.Words provides you with the [LoadOptions](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/) class, which allows more precise control of the load process. Some load formats have a corresponding class that holds load options for this load format, for example, there is [PdfLoadOptions](https://reference.aspose.com/words/net/aspose.words.loading/pdfloadoptions/) for loading to PDF format or [TxtLoadOptions](https://reference.aspose.com/words/net/aspose.words.loading/txtloadoptions/) for loading to TXT. This article provides examples of working with options of the **LoadOptions** class.

## Set Microsoft Word Version to Change the Appearance

Different versions of Microsoft Word application can display documents in differently. For example, there is a well-known problem with OOXML documents such as DOCX or DOTX produced using WPS Office. In such case essential document markup elements may be missing or may be interpreted differently causing Microsoft Word 2019 to show such a document differently compared to Microsoft Word 2010.

By default Aspose.Words opens documents using Microsoft Word 2019 rules. If you need to to make document loading appear as it would happen in one of the previous Microsoft Word application versions, you should explicitly specify the desired version using the [MswVersion](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/mswversion/) property of the **LoadOptions** class.

The following code example shows how to set the Microsoft Word version with load options:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "set-ms-word-version.cs" >}}

## Set Language Preferences to Change the Appearance

The details of displaying a document in Microsoft Word depend not only on the application version and the **MswVersion** property value but also on the language settings. Microsoft Word may show documents differently depending on the "Office Language Preferences" dialog settings, that can be found in "File → Options → Languаge". Using this dialog a user can select, for example, primary language, proofing languages, display languages, and so on. Aspose.Words provides the [LanguagePreferences](https://reference.aspose.com/words/net/aspose.words.loading/languagepreferences/) property as the equivalent of this dialog. If Aspose.Words output differs from the Microsoft Word output, set the appropriate value for **EditingLanguage** – this can improve the output document.

The following code example shows how to set Japanese as **EditingLanguage**:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "add-editing-language.cs" >}}

## Use WarningCallback to Control Problems While Loading a Document

Some documents may be corrupted, contain invalid entries, or have features not currently supported by Aspose.Words. If you want to know about problems that occurred while loading a document, Aspose.Words provides the [IWarningCallback](https://reference.aspose.com/words/net/aspose.words/iwarningcallback/) interface.

The following code example shows the implementation of the **IWarningCallback** interface:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "i-warning-callback.cs" >}}

To get information about all problems throughout the load time, use the [WarningCallback](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/warningcallback/) property.

The following code example shows how to use this property:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "warning-callback.cs" >}}

## Use ResourceLoadingCallback to Control the External Resources Loading

A document may contain external links to images located somewhere on a local disk, network, or Internet. Aspose.Words automatically loads such images into a document, but there are situations when this process needs to be controlled. For example, to decide whether we really need to load a certain image or perhaps skip it. The [ResourceLoadingCallback](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/resourceloadingcallback/) load option allows you to control this.

The following code example shows the implementation of the [IResourceLoadingCallback](https://reference.aspose.com/words/net/aspose.words.loading/iresourceloadingcallback/) interface:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "i-resource-loading-callback.cs" >}}

The following code example shows how to use the **ResourceLoadingCallback** property:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "resource-loading-callback.cs" >}}

## Use TempFolder to Avoid a Memory Exception

Aspose.Words supports extremely large documents that have thousands of pages full of rich content. Loading such documents may require much RAM. In the process of loading, Aspose.Words needs even more memory to hold temporary structures used to parse a document.

If you have a problem with Out of Memory exception while loading a document, try to use the [TempFolder](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/tempfolder/) property. In this case, Aspose.Words will store some data in temporary files instead of memory, and this can help avoid such an exception.

The following code example shows how to set **TempFolder**:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "temp-folder.cs" >}}

## Set the Encoding Explicitly

Most modern document formats store their content in Unicode and do not require special handling. On the other hand, there are still many documents that use some pre‑Unicode encoding and sometimes either miss encoding information or do not even support encoding information by nature. Aspose.Words tries to automatically detect the appropriate encoding by default, but in a rare case you may need to use an encoding different from the one detected by our encoding recognition algorithm. In this case, use the [Encoding](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/encoding/) property to get or set the encoding.

The following code example shows how to set the encoding to override the automatically chosen encoding:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "load-with-encoding.cs" >}}

## Load Encrypted Documents

You can load Word documents encrypted with a password. To do this, use a special constructor overload, which accepts a [LoadOptions](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/) object. This object contains the [Password](https://reference.aspose.com/words/net/aspose.words.loading/loadoptions/password/) property, which specifies the password string.

The following code example shows how to load a document encrypted with a password:

{{< gist "aspose-words-gists" "40be8275fc43f78f5e5877212e4e1bf3" "open-encrypted-document.cs" >}}

If you do not know in advance whether the file is encrypted, you can use the [FileFormatUtil](https://reference.aspose.com/words/net/aspose.words/fileformatutil/) class, which provides utility methods for working with file formats, such as detecting the file format or converting file extensions to/from file format enumerations. To detect if the document is encrypted and requires a password to open it, use the [IsEncrypted](https://reference.aspose.com/words/net/aspose.words/fileformatinfo/isencrypted/) property.

The following code example shows how to verify OpenDocument either it is encrypted or not:

{{< gist "aspose-words-gists" "af95c7a408187bb25cf9137465fe5ce6" "verify-encrypted-document.cs" >}}

------

## FAQ

1. **Q:** How can I specify which Microsoft Word version is used when loading a document?  
   **A:** Set the `MswVersion` property of a `LoadOptions` instance to the desired `MswVersion` enum value (e.g., `MswVersion.Word2007`). Pass this `LoadOptions` object to the `Document` constructor.

2. **Q:** What is the recommended way to open a password‑protected Word file?  
   **A:** Create a `LoadOptions` object, assign the password to its `Password` property, and use the overload `new Document(string fileName, LoadOptions loadOptions)`.

3. **Q:** How do I control the text encoding used when loading a plain‑text document?  
   **A:** Set the `Encoding` property of `LoadOptions` (or `TxtLoadOptions`) to the required `System.Text.Encoding` (e.g., `Encoding.GetEncoding("windows-1252")`) before loading the document.

4. **Q:** How can I receive warnings about problems that occur during the load process?  
   **A:** Implement the `IWarningCallback` interface, assign an instance to the `WarningCallback` property of `LoadOptions`, and then load the document. All warnings will be reported through the callback.

5. **Q:** My application throws an OutOfMemoryException when loading a very large document; what can I do?  
   **A:** Set the `TempFolder` property of `LoadOptions` to a folder on disk. Aspose.Words will write temporary data to this location instead of keeping everything in memory, reducing the risk of memory exhaustion.