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());
	}

 

UK Electronic Designer
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.