Write / Read Data to a File and Exist

Write

private async void WriteTestToFile(string filename, string text)
{
  StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
  StorageFile file = folder.CreateFileAsync(filename, CreationColissionOption.ReplaceExisting);
  await FileIO.WriteTextAsync(file, text);
}

Read

private async Task<string> ReadTestToFile(string filename, string text)
{
  StorageFolder folder = Windows.Storage.ApplicationData.Current.LocalFolder;
  StorageFile file = folder.GetFileAsync(filename);
  string result = await FileIO.ReadTextAsync(file);
  return result;
}

Exist

Use „Read a File“ and handle the Exception if the File does not exists.