# Javascript: TXTextControl.save Method

> Saves the current document in a certain format and sends the result back asynchronously by calling a given callback function.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: TXTextControl.save Method
- **638 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/save-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/save-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/save-method/llms-full.txt

---

### Description

Saves the current document in a certain format and sends the result back asynchronously by calling a given callback function.

### Syntax

```javascript
<void> TXTextControl.save(<StreamType> streamType, <SaveDocumentResultCallback> callback, [<SaveSettings> saveSettings], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| streamType | Specifies one of the numerical [StreamType](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/streamtype-enumeration/llms-full.txt) values. |
| callback | A function with one parameter. Is called with an argument object of type [SaveDocumentResult](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/savedocumentresult/llms-full.txt) containing the document data after the document has been saved successfully. |
| saveSettings | Optional. Specifies additional save settings. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example shows how to save the current document and display the received document data in the console.

```javascript
TXTextControl.save(TXTextControl.StreamType.HTMLFormat, function (e) {
   console.log(e.data);
});

Possible console output:

> <?xml version="1.0" ?>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
[...]
```

The following example demonstrates `TXTextControl.save` in a practical document-editing workflow. It saves the current document in a certain format and sends the result back asynchronously by calling a given callback function.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.save(
    TXTextControl.StreamType.HTMLFormat,
    function(args) {
        if (!args) {
            console.warn("No save document result was returned.");
            return;
        }
        
        console.log("save result:", args);
    },
    { creatorApplication: "Document Editor sample" },
    onTxError
);
```

---

## Nearby

- **Previous:** [Javascript: TXTextControl.RulerBarScaleUnit Enumeration](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/rulerbarscaleunit-enumeration/llms-full.txt)
- **Next:** [Javascript: TXTextControl.saveDocument Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/txtextcontrol/savedocument-method/llms-full.txt)
