# Javascript: EmbeddedFileCollection.addTextFile Method

> Adds an embedded text file to the collection.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 29.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: EmbeddedFileCollection.addTextFile Method
- **585 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/embeddedfilecollection/addtextfile-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/embeddedfilecollection/addtextfile-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/embeddedfilecollection/addtextfile-method/llms-full.txt

---

### Description

Adds an embedded text file to the collection.

### Syntax

```javascript
<void> EmbeddedFileCollection.addTextFile(<string> fileName, <string> data, [<string> metaData], [<EmptyRequestCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| fileName | Specifies the file's name. |
| data | Specifies the file's data as a string. |
| metaData | Optional. Specifies additional metadata with properties of the document which is embedded. The data is added to the metadata of the containing document. The string must consist of one or more rdf:Description elements as specified by the XMP Specification (XMP: Extensible Metadata Platform, Adobe Systems Incorporated) or the RDF Model and Syntax Specification (http://www.w3.org/TR/rdf-syntax-grammar/). rdf is the XML namespace prefix for the "http://www.w3.org/1999/02/22-rdf-syntax-ns#" namespace. It can be null or an empty string, if there is no additional meta data to embed. |
| callback | Optional. Is called when the operation completed. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `EmbeddedFileCollection.addTextFile` in a practical document-editing workflow. It adds an embedded text file to the collection.

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

TXTextControl.textParts.getMainText(function(mainText) {
    const embeddedFiles = mainText.embeddedFiles;
    embeddedFiles.addTextFile(
        "quarterly-report.docx",
        "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAFgAH/qbPzWQAAAABJRU5ErkJggg==",
        "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAFgAH/qbPzWQAAAABJRU5ErkJggg==",
        function() {
            console.log("add text file completed.");
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

- **Previous:** [Javascript: EmbeddedFileCollection.addBinaryFile Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/embeddedfilecollection/addbinaryfile-method/llms-full.txt)
- **Next:** [Javascript: EmbeddedFileCollection.removeElementAt Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/embeddedfilecollection/removeelementat-method/llms-full.txt)
