{"id":262,"date":"2016-12-16T18:26:10","date_gmt":"2016-12-16T18:26:10","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=262"},"modified":"2022-09-13T15:36:42","modified_gmt":"2022-09-13T14:36:42","slug":"working-with-files-temporary-files","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/files\/working-with-files-temporary-files","title":{"rendered":"Working With Files-Temporary Files"},"content":{"rendered":"<h4>\n\tWrite Data To A Temporary File<\/h4>\n<p>This is the same as for local files but using &#8220;TemporaryFolder&#8221; instead.<\/p>\n<p>Windows will automatically delete temporary files. &nbsp;You should assume that they only exist for the current app session.<\/p>\n<pre><code>\nusing Windows.Storage;\n\n\tStorageFolder Folder1 = ApplicationData.Current.TemporaryFolder;\n\tStorageFile File1 = await Folder1.CreateFileAsync(\"SomeFolder\\\\SomeFile.txt\", CreationCollisionOption.ReplaceExisting);\n\tif (File1 != null)\n\t{\n\t\tawait FileIO.WriteTextAsync(File1, \"data\");\n\t}\n<\/code><\/pre>\n<p>File will be saved to:&nbsp;User Files\\LocalAppData\\PackageName\\TempState\\SomeFolder\\SomeFile.txt<\/p>\n<p>To access it programatically, for instance givign a path to somethign that will open it, use the URI: ms-appdata:\/\/\/temp\/SomeFolder\\SomeFile.txt<\/p>\n<h4>\n\tWrite Memory Stream To File<\/h4>\n<pre><code>\n\tStorageFolder Folder1 = ApplicationData.Current.TemporaryFolder;\n\tStorageFile File1 = await Folder1.CreateFileAsync(\"SomeFolder\\\\SomeFile.txt\", CreationCollisionOption.ReplaceExisting);\n\tif (File1 != null)\n\t{\n\t\tMyMemoryStream.Seek(0, SeekOrigin.Begin);\n\t\tawait FileIO.WriteBytesAsync(File1, MyMemoryStream.ToArray());\n\t}\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Write Data To A Temporary File This is the same as for local files but using &#8220;TemporaryFolder&#8221; instead. Windows will automatically delete temporary files. &nbsp;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(&#8220;SomeFolder\\\\SomeFile.txt&#8221;, CreationCollisionOption.ReplaceExisting); if (File1 != null) { await FileIO.WriteTextAsync(File1, [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[135],"tags":[],"class_list":["post-262","post","type-post","status-publish","format-standard","hentry","category-files"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/262","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=262"}],"version-history":[{"count":1,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/262\/revisions"}],"predecessor-version":[{"id":1177,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/262\/revisions\/1177"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=262"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=262"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=262"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}