# File Open

**FileOpen** keeps a file open to speed up a large number of write operations.

This function creates a FileHandle object in its execution path that can be used by the [TextFileWrite](https://docs.linx.software/reference/plugins/file/content/textfilewrite) or [BinaryFileWrite](https://docs.linx.software/reference/plugins/file/content/binaryfilewrite) functions to write to the opened file.

You can also use the [SetValue](https://docs.linx.software/reference/plugins/linx/content/setvalue) function to assign values to the FileHandle's 'Append' property to add content that way. See the [Examples](#examples) below.

## Properties

### File Path

The full path to the file that has to be kept open for writing.

### Is Text

Indicates if the file to open (or create) is a text file.

### Codepage

Only displayed if the **Is Text** property option is checked.

Selects the character encoding to use when writing text to the file.

The default **Codepage** is the one used in your operating system.

### File Does Not Exist

You can opt to create the file or return an error if the file already exists.

### File Exists

Only displayed if the **Is Text** property option is checked.

Specifies what to do if the file already exists.

Options:

* **Append Data**: Any text that is written to the file is added to the end of the file.
* **Increment File Name**: Adds a number to the file name to make it unique, starting with 1.
* **Overwrite File**: Replaces all content in the file with the new content.
* **Throw Exception**: Stops the function's processing and returns an error.

***

## Examples

Suppose you have a long list of lines of text to write to a file. Using the **FileOpen** function, as shown below, will run much quicker than doing it without the **FileOpen** function.

### Use with [TextFileWrite](https://docs.linx.software/reference/plugins/file/content/textfilewrite)

Set the 'File path' property of the **TextFileWrite** function to `FileOpen.File.FileHandle`.

<div align="left"><figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-19467eaed1f375a938385a81b07677d0630ed82a%2Ffileopentextfilewrite.png?alt=media" alt="TextFileWrite"><figcaption></figcaption></figure></div>

### Use with [SetValue](https://docs.linx.software/reference/plugins/linx/content/setvalue)

Set the 'Target' property of the **SetValue** function to `FileOpen.File.FileHandle.Append` or `FileOpen.File.FileHandle.AppendLine`. 'AppendLine' will add a line terminator after the text.

<div align="left"><figure><img src="https://3338214469-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F1nxDeDH8GVCXb0XelqGm%2Fuploads%2Fgit-blob-339965effcb042b2e44decb89eaa482ffee928cd%2Ffileopensetvalue.png?alt=media" alt="SetValue Example"><figcaption></figcaption></figure></div>

***

## Links

* [Wikipedia: Code page](http://en.wikipedia.org/wiki/Code_page)
* [Joel on Character Sets](http://www.joelonsoftware.com/articles/Unicode.html)
* [Microsoft: Code pages](https://docs.microsoft.com/en-us/cpp/c-runtime-library/code-pages)

***
