# SaveText

### Introduction

The SaveText function is a function that can be used to easily save the contents of a string to a .txt file. This function will overwrite previously-created .txt files if an existing file name is passed, so be careful calling this method.

### Code Example

The following code creates a string, saves it to a .txt file, then opens that file.

```
System.Text.StringBuilder builder = new System.Text.StringBuilder();

builder.AppendLine("Why is FlatRedBall so great?  Let me count the reasons...");

// Stop at 100 to prevent an infinite loop :)
for (int i = 1; i < 100; i++)
{
    builder.AppendLine(i.ToString());
}

string fileToSave = FileManager.UserApplicationData + @"\temp.txt";

FileManager.SaveText(builder.ToString(), fileToSave);

System.Diagnostics.Process.Start(fileToSave);
```

![SaveText.png](https://951240982-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M_fye9Ufg3vzJxwX5Hk%2Fuploads%2Fgit-blob-0143c95ec7a491db4dd7e64eb63a8ac2926cba80%2Fmigrated_media-SaveText.png?alt=media)
