# Selection.Save Method

> Saves the selected text of a document with the specified format.

- **Product:** TX Text Control .NET for WPF
- **Section:** Reference
- **Kind:** Method
- **Namespace:** `TXTextControl`
- **Package:** `TXTextControl.TextControl.WPF.SDK` (assembly `TXTextControl.dll`, from the private NuGet feed or Text Control Offline Packages)
- **.NET Framework:** reference `TXTextControl.dll` from the setup
- **Path:** TX Text Control .NET for WPF > Reference > TXTextControl > Selection.Save Method
- **3395 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/save-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/save-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/save-method/llms-full.txt

---

### Description

Saves the selected text of a document with the specified format.

### Syntax

#### Save()

Opens a file save dialogbox and saves the selected text of a document in a file.

```csharp
public Selection.DialogResult Save();
```

```vbnet
Public Function Save() As Selection.DialogResult
```

#### Save(StreamType)

Opens a file save dialogbox and saves the selected text of a document in a file with the specified format.

```csharp
public Selection.DialogResult Save(StreamType streamType);
```

```vbnet
Public Function Save(streamType As StreamType) As Selection.DialogResult
```

| Parameter | Description |
|---|---|
| streamType | Specifies one of the [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) values. |

#### Save(string, StreamType)

Saves the selected text of a document in the specified file with the specified format.

```csharp
public void Save(string path, StreamType streamType);
```

```vbnet
Public Sub Save(path As String, streamType As StreamType)
```

| Parameter | Description |
|---|---|
| path | Specifies a file into which the selection is saved. If the file does not exist, it is created. If the file exists, its contents are overwritten. |
| streamType | Specifies one of the [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) values. |

#### Save(FileStream, StreamType)

Saves the selected text of a document in the specified file stream with the specified format.

```csharp
public void Save(FileStream fileStream, StreamType streamType);
```

```vbnet
Public Sub Save(fileStream As FileStream, streamType As StreamType)
```

| Parameter | Description |
|---|---|
| fileStream | Specifies a file into which the selection is saved. The data is saved at the stream's current position. |
| streamType | Specifies one of the [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) values. |

#### Save(out byte\[\], BinaryStreamType)

Saves the selected text of a document in the specified byte array with the specified format.

```csharp
public void Save(out byte[] binaryData, BinaryStreamType binaryStreamType);
```

```vbnet
Public Sub Save(ByRef binaryData As Byte(), binaryStreamType As BinaryStreamType)
```

| Parameter | Description |
|---|---|
| binaryData | Specifies a byte array into which the selection is saved. No memory needs to be allocated through the caller. |
| binaryStreamType | Specifies one of the [BinaryStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/binarystreamtype/enumeration/llms-full.txt) values. |

#### Save(out string, StringStreamType)

Saves the selected text of a document as a string with the specified format.

```csharp
public void Save(out string stringData, StringStreamType stringStreamType);
```

```vbnet
Public Sub Save(ByRef stringData As String, stringStreamType As StringStreamType)
```

| Parameter | Description |
|---|---|
| stringData | Specifies a string into which the selection is saved. No memory needs to be allocated through the caller. |
| stringStreamType | Specifies one of the [StringStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/stringstreamtype/enumeration/llms-full.txt) values. |

#### Save(StreamType, SaveSettings)

Opens a file save dialogbox and saves the selected text of a document in a file with the specified format and special settings.

```csharp
public Selection.DialogResult Save(StreamType streamType, SaveSettings saveSettings);
```

```vbnet
Public Function Save(streamType As StreamType, saveSettings As SaveSettings) As Selection.DialogResult
```

| Parameter | Description |
|---|---|
| streamType | Specifies one of the [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) values. |
| saveSettings | Specifies a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/llms-full.txt) object with additional information and settings for the save operation. |

#### Save(string, StreamType, SaveSettings)

Saves the selected text of a document in the specified file using the specified format and special settings.

```csharp
public void Save(string path, StreamType streamType, SaveSettings saveSettings);
```

```vbnet
Public Sub Save(path As String, streamType As StreamType, saveSettings As SaveSettings)
```

| Parameter | Description |
|---|---|
| path | Specifies a file into which the selection is saved. If the file does not exist, it is created. If the file exists, its contents are overwritten. |
| streamType | Specifies one of the [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) values. |
| saveSettings | Specifies a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/llms-full.txt) object with additional information and settings for the save operation. |

#### Save(FileStream, StreamType, SaveSettings)

Saves the selected text of a document in the specified file stream using the specified format and special settings.

```csharp
public void Save(FileStream fileStream, StreamType streamType, SaveSettings saveSettings);
```

```vbnet
Public Sub Save(fileStream As FileStream, streamType As StreamType, saveSettings As SaveSettings)
```

| Parameter | Description |
|---|---|
| fileStream | Specifies a file into which the selection is saved. The data is saved at the stream's current position. |
| streamType | Specifies one of the [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/streamtype/enumeration/llms-full.txt) values. |
| saveSettings | Specifies a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/llms-full.txt) object with additional information and settings for the save operation. |

#### Save(out byte\[\], BinaryStreamType, SaveSettings)

Saves the selected text of a document in the specified byte array using the specified format and special settings.

```csharp
public void Save(out byte[] binaryData, BinaryStreamType binaryStreamType, SaveSettings saveSettings);
```

```vbnet
Public Sub Save(ByRef binaryData As Byte(), binaryStreamType As BinaryStreamType, saveSettings As SaveSettings)
```

| Parameter | Description |
|---|---|
| binaryData | Specifies a byte array into which the selection is saved. No memory needs to be allocated through the caller. |
| binaryStreamType | Specifies one of the [BinaryStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/binarystreamtype/enumeration/llms-full.txt) values. |
| saveSettings | Specifies a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/llms-full.txt) object with additional information and settings for the save operation. |

#### Save(out string, StringStreamType, SaveSettings)

Saves the selected text of a document as a string using the specified format and special settings.

```csharp
public void Save(out string stringData, StringStreamType stringStreamType, SaveSettings saveSettings);
```

```vbnet
Public Sub Save(ByRef stringData As String, stringStreamType As StringStreamType, saveSettings As SaveSettings)
```

| Parameter | Description |
|---|---|
| stringData | Specifies a string into which the selection is saved. No memory needs to be allocated through the caller. |
| stringStreamType | Specifies one of the [StringStreamType](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/stringstreamtype/enumeration/llms-full.txt) values. |
| saveSettings | Specifies a [SaveSettings](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/savesettings/llms-full.txt) object with additional information and settings for the save operation. |

### Return Value

The implementations which open a dialog box return a [Selection.DialogResult](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/dialogresult-enumeration/llms-full.txt) value.

### Examples

The following example formats the heading of a short document by using `Selection.Save`.

```csharp
textControl.Text = "Quarterly results\nRevenue increased by 12%.";
textControl.Select(0, 17);
Selection selection = textControl.Selection;

selection.Save("document.docx", StreamType.WordprocessingML);
Console.WriteLine("Selection is ready for use.");
```

```vbnet
textControl.Text = "Quarterly results" & vbCrLf & "Revenue increased by 12%."
textControl.Select(0, 17)
Dim selection As Selection = textControl.Selection

selection.Save("document.docx", StreamType.WordprocessingML)
Console.WriteLine("Selection is ready for use.")
```

### Remarks

The methods opening a dialog box are not available through the [Selection](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/llms-full.txt) object of a [ServerTextControl](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/llms-full.txt).

---

## Nearby

- **Previous:** [Selection.RemoveInlineStyles Method](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/removeinlinestyles-method/llms-full.txt)
- **Next:** [Selection.SectionFormat Property](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/selection/sectionformat-property/llms-full.txt)
