Write Data To A Temporary File
This is the same as for local files but using “TemporaryFolder” instead.
Windows will automatically delete temporary files. You should assume that they only exist for the current app session.
using Windows.Storage;
StorageFolder Folder1 = ApplicationData.Current.TemporaryFolder;
StorageFile File1 = await Folder1.CreateFileAsync("SomeFolder\\SomeFile.txt", CreationCollisionOption.ReplaceExisting);
if (File1 != null)
{
await FileIO.WriteTextAsync(File1, "data");
}
File will be saved to: User Files\LocalAppData\PackageName\TempState\SomeFolder\SomeFile.txt
To access it programatically, for instance givign a path to somethign that will open it, use the URI: ms-appdata:///temp/SomeFolder\SomeFile.txt
Write Memory Stream To File
StorageFolder Folder1 = ApplicationData.Current.TemporaryFolder;
StorageFile File1 = await Folder1.CreateFileAsync("SomeFolder\\SomeFile.txt", CreationCollisionOption.ReplaceExisting);
if (File1 != null)
{
MyMemoryStream.Seek(0, SeekOrigin.Begin);
await FileIO.WriteBytesAsync(File1, MyMemoryStream.ToArray());
}
