Here are 2 options:
private async void btnSave_Click(object sender, RoutedEventArgs e)
{
string content = txtUserInput.Text;
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile targetFile = await localFolder.CreateFileAsync("MyFile.txt", CreationCollisionOption.ReplaceExisting);
if (targetFile != null)
{
/* Option 1 */
using (StreamWriter SW = new StreamWriter(await targetFile.OpenStreamForWriteAsync()))
{
SW.WriteLine(content);
}
/**/
/* Option 2 */
//await FileIO.WriteTextAsync(targetFile, content);
/**/
}
}
private async void btnLoad_Click(object sender, RoutedEventArgs e)
{
string content = string.Empty;
StorageFolder localFolder = ApplicationData.Current.LocalFolder;
StorageFile targetFile = await localFolder.CreateFileAsync("MyFile.txt", CreationCollisionOption.OpenIfExists);
if (targetFile != null)
{
/* Option 1 */
using (StreamReader SW = new StreamReader(await targetFile.OpenStreamForReadAsync()))
{
content = await SW.ReadToEndAsync();
}
/**/
/* Option 2 */
//content = await FileIO.ReadTextAsync(targetFile);
/**/
}
txtUserInput.Text = content;
}
You can refer following link for details:
Quickstart: Reading and writing files
If a post solves the problem you asked, please mark it as Answer.