---
url: >-
  /statelake/scripting-reference/functions-and-procedures/file-functions/savetofile.md
---

# SaveToFile

**SaveToFile** saves the string given by **aContents** as a file on disk named as specified by **aFileName**. Also see [LoadFileToString](/flow/guide/scripting-reference/functions/file/loadfiletostring).

**SaveToFile** does not handle unicode characters. Rather, use the WideString version **SaveWideStringToFile**. Please also see [SaveWideStringToFile](/statelake/scripting-reference/functions-and-procedures/file-functions/savewidestringtofile).

If a file with **aFileName** already exists, then it will be overwritten - if attributes and permissions allow. If permissions and attributes do not allow it to be overwritten, then an exception error will be encountered.

**Declaration**: Procedure SaveToFile(const aContents, aFileName : string)

A good example as below.

```pascal
procedure OnMapEvent(var Value:Variant);
 var vData : string;
begin
  vData := 'abcde';
  SaveToFile(vData, 'c:\Temp\TodayTest.txt');
end;
```
