TextRange.Save 메서드

정의

현재 선택 영역을 지정된 데이터 형식으로 지정된 스트림에 저장합니다.

오버로드

Name Description
Save(Stream, String)

현재 선택 영역을 지정된 데이터 형식으로 지정된 스트림에 저장합니다.

Save(Stream, String, Boolean)

사용자 지정 TextElement 개체를 유지하는 옵션을 사용하여 현재 선택 영역을 지정된 데이터 형식으로 지정된 스트림에 저장합니다.

Save(Stream, String)

현재 선택 영역을 지정된 데이터 형식으로 지정된 스트림에 저장합니다.

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)

매개 변수

stream
Stream

현재 선택 영역을 저장할 쓰기 가능한 빈 스트림입니다.

dataFormat
String

현재 선택 영역을 저장할 데이터 형식입니다. 현재 지원되는 데이터 형식은 Rtf, Text, XamlXamlPackage.

예외

stream 또는 dataFormat .입니다 null.

지정된 데이터 형식은 지원되지 않습니다.

-또는

로드된 콘텐츠가 stream 지정된 데이터 형식과 일치하지 않습니다.

예제

다음 예제에서는 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

설명

이 메서드가 반환 stream 되면 열린 상태로 남아 있고 내 stream 의 현재 위치는 정의되지 않습니다.

저장 작업의 일부로 현재 선택 영역의 콘텐츠가 에 지정된 dataFormat데이터 형식으로 변환될 수 있습니다.

추가 정보

적용 대상

Save(Stream, String, Boolean)

사용자 지정 TextElement 개체를 유지하는 옵션을 사용하여 현재 선택 영역을 지정된 데이터 형식으로 지정된 스트림에 저장합니다.

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)

매개 변수

stream
Stream

현재 선택 영역을 저장할 쓰기 가능한 빈 스트림입니다.

dataFormat
String

현재 선택 영역을 저장할 데이터 형식입니다. 현재 지원되는 데이터 형식은 Rtf, Text, XamlXamlPackage.

preserveTextElements
Boolean

사용자 지정 개체를 유지하려면 /&이고, 그렇지 않으면 .입니다.

예외

을 사용하는 경우 발생 streamdataFormat합니다null.

지정된 데이터 형식이 지원되지 않는 경우에 발생합니다. 로드된 stream 콘텐츠가 지정된 데이터 형식과 일치하지 않는 경우에도 발생할 수 있습니다.

설명

이 경우 preserveTextElementsfalse사용자 지정 TextElement 개체는 알려진 TextElement 형식으로 저장됩니다. 예를 들어 TextElementHeading1Paragraph. 이 메서드를 호출할 때 이 메서드 preserveTextElementsfalseHeading1저장되는 경우 ParagraphTextRange 변환됩니다. 로 설정된 상태에서 이 메서드 preserveTextElementstrueHeading1 호출하면 변환되지 않고 저장됩니다. 사용자 지정 텍스트 요소를 dataFormat 유지하려면 .로 설정 DataFormats.Xaml해야 합니다.

Save(Stream, String, Boolean) .NET Framework 버전 3.5에 도입되었습니다. 자세한 내용은 버전 및 종속성을 참조하세요.

적용 대상