TextRange.Save Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee wordt de huidige selectie opgeslagen in een opgegeven stroom in een opgegeven gegevensindeling.
Overloads
| Name | Description |
|---|---|
| Save(Stream, String) |
Hiermee wordt de huidige selectie opgeslagen in een opgegeven stroom in een opgegeven gegevensindeling. |
| Save(Stream, String, Boolean) |
Hiermee wordt de huidige selectie opgeslagen in een opgegeven stroom in een opgegeven gegevensindeling, met de optie om aangepaste TextElement objecten te behouden. |
Save(Stream, String)
Hiermee wordt de huidige selectie opgeslagen in een opgegeven stroom in een opgegeven gegevensindeling.
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)
Parameters
- stream
- Stream
Een lege, beschrijfbare stroom om de huidige selectie op te slaan.
- dataFormat
- String
Een gegevensindeling om de huidige selectie op te slaan als. Momenteel ondersteunde gegevensindelingen zijn Rtf, Text, Xamlen XamlPackage.
Uitzonderingen
stream of dataFormat is null.
De opgegeven gegevensindeling wordt niet ondersteund.
-of
Inhoud die wordt geladen, stream komt niet overeen met de opgegeven gegevensindeling.
Voorbeelden
In het volgende voorbeeld ziet u het gebruik van de methode 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
Opmerkingen
Wanneer deze methode wordt geretourneerd, stream blijft deze open en is de huidige positie binnen stream niet gedefinieerd.
Als onderdeel van de opslagbewerking kan inhoud in de huidige selectie worden geconverteerd naar de gegevensindeling die is opgegeven door dataFormat.
Zie ook
Van toepassing op
Save(Stream, String, Boolean)
Hiermee wordt de huidige selectie opgeslagen in een opgegeven stroom in een opgegeven gegevensindeling, met de optie om aangepaste TextElement objecten te behouden.
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)
Parameters
- stream
- Stream
Een lege, beschrijfbare stroom om de huidige selectie op te slaan.
- dataFormat
- String
Een gegevensindeling om de huidige selectie op te slaan als. Momenteel ondersteunde gegevensindelingen zijn Rtf, Text, Xamlen XamlPackage.
- preserveTextElements
- Boolean
trueom aangepaste TextElement objecten te behouden; anders. false
Uitzonderingen
Treedt op wanneer stream of dataFormat is null.
Treedt op wanneer de opgegeven gegevensindeling niet wordt ondersteund. Kan ook worden gegenereerd als inhoud die wordt stream geladen niet overeenkomt met de opgegeven gegevensindeling.
Opmerkingen
Wanneer preserveTextElements is false, worden aangepaste TextElement objecten opgeslagen als bekende TextElement typen. Stel dat u een aangepaste TextElement aangeroepen naam Heading1maakt, waarvan u de naam Paragraphovergeeft. Wanneer u deze methode aanroept met preserveTextElements ingesteld op false, Heading1 wordt deze geconverteerd naar een Paragraph methode wanneer deze TextRange wordt opgeslagen. Wanneer u deze methode aanroept met preserveTextElements ingesteld op true, Heading1 wordt opgeslagen zonder dat deze wordt geconverteerd. Als u aangepaste tekstelementen wilt behouden, dataFormat moet u deze instellen op DataFormats.Xaml.
Save(Stream, String, Boolean) wordt geïntroduceerd in de .NET Framework versie 3.5. Zie Versies en afhankelijkheden voor meer informatie.