appxmanifest

Declaring file types you want your application to be able to see In Solution Explorer open Package.appxmanifest > Declarations > File Type Associations In Properties > Name, give this declaration section a name. E.g. “resource_files” Then in the Supported file type section Content type: can be blank File Type: the file extentions (e.g. “.mp3”) Add […]

Read More

Working With Files-OS

Select Folder StorageFolder Folder1 = await StorageFolder.GetFolderFromPathAsync(“C:\\SomeFolder”); Accessing System Folders Not all folders are accesible by Universal Windows Apps. To make a folder accesible to a UWP app, you can use FolderPermissions command line tool. E.g., give UWP apps access to c:\test folder: FolderPermissions c:\test -e Note this will work only with native Win32 apis […]

Read More

Assets

Adding files to assets You need to right click the Assets folder in Visual Studio and select Add existing item (you can’t just copy files into the folder in explorer) Files That Were Packaged With Your App (Assets)

Read More

Working With Directories-Local Folder

  Create Folder If It Doesn’t Exist //ENSURE FOLDER EXISTS if (await ApplicationData.Current.LocalFolder.TryGetItemAsync(“MySubFolder”) == null) await ApplicationData.Current.LocalFolder.CreateFolderAsync(“MySubFolder”); Delete All Files In A Folder //DELETE ALL THE FILES StorageFolder Folder1 = await ApplicationData.Current.LocalFolder.GetFolderAsync(“MySubFolder”); IReadOnlyList<StorageFile> FilesToBeDeleted = await Folder1.GetFilesAsync(); if (FilesToBeDeleted != null) { foreach (StorageFile FileToDelete in FilesToBeDeleted) await FileToDelete.DeleteAsync(StorageDeleteOption.PermanentDelete); } Look For Folders StorageFolder UsbDrive […]

Read More

USB Drives, Memory Sticks, etc

Enabling Access Of USB Drive Files These are located in: Windows.Storage.KnownFolders.RemovableDevices You will need manifest permissions to access though: Open Package.appxmanifest > Capabilities > Enable ‘Removable Storage’ You also have to declare what files types you will work with (or you will get Access is denied exception errors when trying to access RemovableDevices): Open Package.appxmanifest > Declarations […]

Read More

Working With Files-LocalFolder

Filepath for object that just want a string use the URI: ms-appdata:///local/SomeFolder\SomeFile.png Does File Exist Using await (note this is not good in loops etc as await doesn’t truly await!!) or Write Data To A Local File File will be saved to: User Files\LocalAppData\PackageName\LocalState\SomeFolder\SomeFile.txt Add String Array To A Local File Each string is added as […]

Read More

Text Files

Add Lines To Text File & Read Back Line By Line StorageFolder Folder1 = ApplicationData.Current.LocalFolder; StorageFile File1 = await Folder1.CreateFileAsync(“MyFolder\\MyFile.txt”, CreationCollisionOption.OpenIfExists); if (File1 != null) { string[] TagIds = new string[1]; TagIds[0] = NewRfidTagId; await FileIO.AppendLinesAsync(File1, TagIds); } StorageFolder Folder1 = ApplicationData.Current.LocalFolder; if (Folder1.TryGetItemAsync(“MyFolder\\MyFile.txt”) != null) { //File Exists StorageFile File1 = await Folder1.GetFileAsync(“MyFolder\\MyFile.txt”); var […]

Read More

Working With Files-Temporary Files

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, […]

Read More

ApplicationData For Settings, Scores, Etc

ApplicationDataContainer values can be: bool, byte, int, uint, long, ulong, float, double, or string using Windows.Storage; Write Settings //—– STORE APP SETTINGS —– ApplicationDataContainer AppDataLocalSettings = ApplicationData.Current.LocalSettings; AppDataLocalSettings.Values[“MyInt”] = 5; AppDataLocalSettings.Values[“MyBool”] = true; AppDataLocalSettings.Values[“MyString”] = “Hello”; Read Settings Null is returned if setting does not exist //—– READ APP SETTINGS —– int SomeInt; bool SomeBool; […]

Read More

.File and Folder Locations

File And Folder Locations App Data Private data that an app reads and writes.  Normally not directly exposed to users, and one app cannot view app data from another app. When an app is uninstalled all of its app data automatically gets deleted as well. There are two types: app settings Access available via the Windows.Storage.ApplicationData class. […]

Read More