TextRange.Save Método

Definición

Guarda la selección actual en una secuencia especificada en un formato de datos especificado.

Sobrecargas

Nombre Description
Save(Stream, String)

Guarda la selección actual en una secuencia especificada en un formato de datos especificado.

Save(Stream, String, Boolean)

Guarda la selección actual en una secuencia especificada en un formato de datos especificado, con la opción de conservar objetos TextElement personalizados.

Save(Stream, String)

Guarda la selección actual en una secuencia especificada en un formato de datos especificado.

public:
 void Save(System::IO::Stream ^ stream, System::String ^ dataFormat);
public void Save(System.IO.Stream stream, string dataFormat);
member this.Save : System.IO.Stream * string -> unit
Public Sub Save (stream As Stream, dataFormat As String)

Parámetros

stream
Stream

Secuencia de escritura vacía en la que guardar la selección actual.

dataFormat
String

Formato de datos para guardar la selección actual como. Actualmente, los formatos de datos admitidos son Rtf, Text, Xamly XamlPackage.

Excepciones

stream o dataFormat es null.

No se admite el formato de datos especificado.

-o

El contenido cargado desde stream no coincide con el formato de datos especificado.

Ejemplos

En el siguiente ejemplo se muestra el uso del método Save.

// This method accepts an input stream and a corresponding data format.  The method
// will attempt to load the input stream into a TextRange selection, apply Bold formatting
// to the selection, save the reformatted selection to an alternat stream, and return 
// the reformatted stream.  
Stream BoldFormatStream(Stream inputStream, string dataFormat)
{
    // A text container to read the stream into.
    FlowDocument workDoc = new FlowDocument();
    TextRange selection = new TextRange(workDoc.ContentStart, workDoc.ContentEnd);
    Stream outputStream = new MemoryStream();

    try
    {
        // Check for a valid data format, and then attempt to load the input stream
        // into the current selection.  Note that CanLoad ONLY checks whether dataFormat
        // is a currently supported data format for loading a TextRange.  It does not 
        // verify that the stream actually contains the specified format.  An exception 
        // may be raised when there is a mismatch between the specified data format and 
        // the data in the stream. 
        if (selection.CanLoad(dataFormat))
            selection.Load(inputStream, dataFormat);
    }
    catch (Exception e) { return outputStream; /* Load failure; return a null stream. */ }

    // Apply Bold formatting to the selection, if it is not empty.
    if (!selection.IsEmpty)
        selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold);

    // Save the formatted selection to a stream, and return the stream.
    if (selection.CanSave(dataFormat))
        selection.Save(outputStream, dataFormat);

    return outputStream;
}
' This method accepts an input stream and a corresponding data format.  The method
' will attempt to load the input stream into a TextRange selection, apply Bold formatting
' to the selection, save the reformatted selection to an alternat stream, and return 
' the reformatted stream.  
Private Function BoldFormatStream(ByVal inputStream As Stream, ByVal dataFormat As String) As Stream
    ' A text container to read the stream into.
    Dim workDoc As New FlowDocument()
    Dim selection As New TextRange(workDoc.ContentStart, workDoc.ContentEnd)
    Dim outputStream As Stream = New MemoryStream()

    Try
        ' Check for a valid data format, and then attempt to load the input stream
        ' into the current selection.  Note that CanLoad ONLY checks whether dataFormat
        ' is a currently supported data format for loading a TextRange.  It does not 
        ' verify that the stream actually contains the specified format.  An exception 
        ' may be raised when there is a mismatch between the specified data format and 
        ' the data in the stream. 
        If selection.CanLoad(dataFormat) Then
            selection.Load(inputStream, dataFormat)
        End If
    Catch e As Exception ' Load failure return a null stream. 
        Return outputStream
    End Try

    ' Apply Bold formatting to the selection, if it is not empty.
    If Not selection.IsEmpty Then
        selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold)
    End If

    ' Save the formatted selection to a stream, and return the stream.
    If selection.CanSave(dataFormat) Then
        selection.Save(outputStream, dataFormat)
    End If

    Return outputStream
End Function

Comentarios

Cuando este método devuelve , stream se deja abierto y la posición actual dentro stream de no está definida.

Como parte de la operación de guardado, el contenido de la selección actual se puede convertir al formato de datos especificado por dataFormat.

Consulte también

Se aplica a

Save(Stream, String, Boolean)

Guarda la selección actual en una secuencia especificada en un formato de datos especificado, con la opción de conservar objetos TextElement personalizados.

public:
 void Save(System::IO::Stream ^ stream, System::String ^ dataFormat, bool preserveTextElements);
public void Save(System.IO.Stream stream, string dataFormat, bool preserveTextElements);
member this.Save : System.IO.Stream * string * bool -> unit
Public Sub Save (stream As Stream, dataFormat As String, preserveTextElements As Boolean)

Parámetros

stream
Stream

Secuencia de escritura vacía en la que guardar la selección actual.

dataFormat
String

Formato de datos para guardar la selección actual como. Actualmente, los formatos de datos admitidos son Rtf, Text, Xamly XamlPackage.

preserveTextElements
Boolean

true es para conservar objetos personalizados TextElement ; de lo contrario, falsees .

Excepciones

Se produce cuando stream o dataFormat es null.

Se produce cuando no se admite el formato de datos especificado. También se puede generar si el contenido cargado desde stream no coincide con el formato de datos especificado.

Comentarios

Cuando preserveTextElements es false, los objetos personalizados TextElement se guardan como tipos conocidos TextElement . Por ejemplo, supongamos que crea un personalizado TextElement denominado Heading1, que hereda de Paragraph. Cuando se llama a este método con establecido preserveTextElementsen false , Heading1 se convierte en cuando ParagraphTextRange se guarda . Cuando se llama a este método con establecido preserveTextElementsen true , Heading1 se guarda sin convertirse. Para conservar los elementos de texto personalizados, dataFormat debe establecerse en DataFormats.Xaml.

Save(Stream, String, Boolean) se introduce en la versión 3.5 de .NET Framework. Para obtener más información, vea Versiones y dependencias.

Se aplica a