This documentation is archived and is not being maintained.

TextRange.Save Method (Stream, String, Boolean)

Saves the current selection to a specified stream in a specified data format, with the option of preserving custom TextElement objects.

Namespace:  System.Windows.Documents
Assembly:  PresentationFramework (in PresentationFramework.dll)

public void Save(
	Stream stream,
	string dataFormat,
	bool preserveTextElements


Type: System.IO.Stream
An empty, writable stream to save the current selection to.
Type: System.String
A data format to save the current selection as. Currently supported data formats are DataFormats.Rtf, DataFormats.Text, DataFormats.Xaml, and DataFormats.XamlPackage.
Type: System.Boolean
true to preserve custom TextElement objects; otherwise, false.


Occurs when stream or dataFormat is null.


Occurs when the specified data format is unsupported. May also be raised if content loaded from stream does not match the specified data format.

When preserveTextElements is false, custom TextElement objects are saved as known TextElement types. For example, suppose you create a custom TextElement called Heading1, which inherits from Paragraph. When you call this method with preserveTextElements set to false, Heading1 is converted to a Paragraph when the TextRange is saved. When you call this method with preserveTextElements set to true, Heading1 is saved without being converted. To preserve custom text elements, dataFormat must be set to DataFormats.Xaml.

Save(Stream, String, Boolean) is introduced in the .NET Framework version 3.5. For more information, see .NET Framework Versions and Dependencies.

.NET Framework

Supported in: 4, 3.5 SP1, 3.0 SP1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.