public static Task <bool> IsKnownFolderFileExistsAsync( KnownFolderId knownFolderId, string fileName) { StorageFolder workingFolder = StorageFileHelper.GetFolderFromKnownFolderId(knownFolderId); return(workingFolder.IsFileExistsAsync(fileName)); }
/// <summary> /// Gets a stream to a specified file from the application local cache folder. /// </summary> /// <param name="knownFolderId">The well known folder ID to use</param> /// <param name="fileName">Relative name of the file to open. Can contains subfolders.</param> /// <param name="accessMode">File access mode. Default is read.</param> /// <returns>The file stream</returns> public static Task <IRandomAccessStream> GetKnowFoldersFileStreamAsync( KnownFolderId knownFolderId, string fileName, FileAccessMode accessMode = FileAccessMode.Read) { StorageFolder workingFolder = StorageFileHelper.GetFolderFromKnownFolderId(knownFolderId); return(GetFileStreamAsync(fileName, accessMode, workingFolder)); }
/// <summary> /// Saves an object inside a file. /// There is no limitation to use this method (refers to <see cref="Save{T}(string, T)"/> method for simple objects). /// </summary> /// <typeparam name="T">Type of object saved</typeparam> /// <param name="filePath">Path to the file that will contain the object</param> /// <param name="value">Object to save</param> /// <returns>The <see cref="StorageFile"/> where the object was saved</returns> public Task <StorageFile> SaveFileAsync <T>(string filePath, T value) { return(StorageFileHelper.WriteTextToFileAsync(Folder, JsonConvert.SerializeObject(value), filePath, CreationCollisionOption.ReplaceExisting)); }
/// <summary> /// Retrieves an object from a file. /// </summary> /// <typeparam name="T">Type of object retrieved</typeparam> /// <param name="filePath">Path to the file that contains the object</param> /// <param name="default">Default value of the object</param> /// <returns>Waiting task until completion with the object in the file</returns> public async Task <T> ReadFileAsync <T>(string filePath, T @default = default(T)) { string value = await StorageFileHelper.ReadTextFromFileAsync(Folder, filePath); return((value != null) ? JsonConvert.DeserializeObject <T>(value) : @default); }
/// <summary> /// Saves an object inside a file. /// There is no limitation to use this method (refers to <see cref="Save{T}(string, T)"/> method for simple objects). /// </summary> /// <typeparam name="T">Type of object saved</typeparam> /// <param name="filePath">Path to the file that will contain the object</param> /// <param name="value">Object to save</param> /// <returns>The <see cref="StorageFile"/> where the object was saved</returns> public Task <StorageFile> SaveFileAsync <T>(string filePath, T value) { return(StorageFileHelper.WriteTextToFileAsync(Folder, serializer.Serialize(value)?.ToString(), filePath, CreationCollisionOption.ReplaceExisting)); }
private async Task <T?> ReadFileAsync <T>(StorageFolder folder, string filePath, T? @default = default) { string value = await StorageFileHelper.ReadTextFromFileAsync(folder, filePath); return((value != null) ? this.Serializer.Deserialize <T>(value) : @default); }
private async Task <StorageFile> CreateFileAsync <T>(StorageFolder folder, string filePath, T value) { return(await StorageFileHelper.WriteTextToFileAsync(folder, Serializer.Serialize(value)?.ToString(), NormalizePath(filePath), CreationCollisionOption.ReplaceExisting)); }