private static Encoding UwpEncodingToSystemEncoding(UwpUnicodeEncoding encoding) { switch (encoding) { case UwpUnicodeEncoding.Utf8: return(Encoding.UTF8); case UwpUnicodeEncoding.Utf16LE: return(Encoding.Unicode); case UwpUnicodeEncoding.Utf16BE: return(Encoding.BigEndianUnicode); } return(Encoding.UTF8); }
/// <summary> /// Writes lines of text to the specified file using the specified character encoding. /// </summary> /// <param name="file">The file that the lines are written to.</param> /// <param name="lines">The list of text strings to write as lines.</param> /// <param name="encoding">The character encoding of the file.</param> /// <returns>No object or value is returned when this method completes.</returns> public static IAsyncAction WriteLinesAsync(IStorageFile file, IEnumerable <string> lines, UwpUnicodeEncoding encoding) => WriteTextAsync(file, ConvertLinesToString(lines), encoding);
/// <summary> /// Writes text to the specified file using the specified character encoding. /// </summary> /// <param name="file">The file that the text is written to.</param> /// <param name="contents">The text to write.</param> /// <param name="encoding">The character encoding of the file.</param> /// <returns>No object or value is returned when this method completes.</returns> public static IAsyncAction WriteTextAsync(IStorageFile file, string contents, UwpUnicodeEncoding encoding) => WriteTextTaskAsync(file, contents, append: false, encoding).AsAsyncAction();
/// <summary> /// Reads the contents of the specified file using the specified character encoding and returns lines of text. /// </summary> /// <param name="file">The file to read.</param> /// <param name="encoding">The character encoding to use.</param> /// <returns>When this method completes successfully, it returns the contents of the file as a list /// (type <see cref="IList{string}" />) of lines of text. Each line of text in the list is represented /// by a <see cref="string"/> object.</returns> public static IAsyncOperation <IList <string> > ReadLinesAsync(IStorageFile file, UwpUnicodeEncoding encoding) => ReadLinesTaskAsync(file, encoding).AsAsyncOperation();
/// <summary> /// Reads the contents of the specified file using the specified character /// encoding and returns text. /// </summary> /// <param name="file">The file to read.</param> /// <param name="encoding">The character encoding to use.</param> /// <returns>When this method completes successfully, it returns the contents /// of the file as a text string.</returns> public static IAsyncOperation <string> ReadTextAsync(IStorageFile file, UwpUnicodeEncoding encoding) => ReadTextTaskAsync(file, encoding).AsAsyncOperation();
/// <summary> /// Writes text to the specified file using the specified character encoding. /// </summary> /// <param name="file">The file that the text is written to.</param> /// <param name="contents">The text to write.</param> /// <param name="encoding">The character encoding of the file.</param> /// <returns>No object or value is returned when this method completes.</returns> public static IAsyncAction WriteTextAsync(IStorageFile file, string contents, UwpUnicodeEncoding encoding) => AsyncAction.FromTask(cancellationToken => WriteTextTaskAsync(file, contents, append: false, recognizeEncoding: true, cancellationToken, encoding));
/// <summary> /// Writes lines of text to the specified file using the specified character encoding. /// </summary> /// <param name="file">The file that the lines are written to.</param> /// <param name="lines">The list of text strings to write as lines.</param> /// <param name="encoding">The character encoding of the file.</param> /// <returns>No object or value is returned when this method completes.</returns> public static IAsyncAction WriteLinesAsync(IStorageFile file, IEnumerable <string> lines, UwpUnicodeEncoding encoding) => AsyncAction.FromTask(cancellationToken => WriteLinesTaskAsync(file, lines, append: false, recognizeEncoding: true, cancellationToken, encoding));
/// <summary> /// Reads the contents of the specified file using the specified character encoding and returns lines of text. /// </summary> /// <param name="file">The file to read.</param> /// <param name="encoding">The character encoding to use.</param> /// <returns>When this method completes successfully, it returns the contents of the file as a list /// (type <see cref="IList{string}" />) of lines of text. Each line of text in the list is represented /// by a <see cref="string"/> object.</returns> public static IAsyncOperation <IList <string> > ReadLinesAsync(IStorageFile file, UwpUnicodeEncoding encoding) => AsyncOperation.FromTask(cancellationToken => ReadLinesTaskAsync(file, cancellationToken, encoding));
public static async Task <bool> SaveFileAsync(StorageFile file, string content, Windows.Storage.Streams.UnicodeEncoding encoding) { // Prevent updates to the remote version of the file until we finish making changes and call CompleteUpdatesAsync. CachedFileManager.DeferUpdates(file); // write to file await FileIO.WriteTextAsync(file, file.Name, encoding); // Let Windows know that we're finished changing the file so the other app can update the remote version of the file. // Completing updates may require Windows to ask for user input. var status = await CachedFileManager.CompleteUpdatesAsync(file); return(status == FileUpdateStatus.Complete); }
public static IAsyncOperation <IList <string> > ReadLinesAsync(string absolutePath, UwpUnicodeEncoding encoding) => AsyncOperation.FromTask(cancellationToken => ReadLinesTaskAsync(absolutePath, cancellationToken, encoding));
public static IAsyncAction AppendTextAsync(string absolutePath, string contents, UwpUnicodeEncoding encoding) => AsyncAction.FromTask(cancellationToken => AppendTextTaskAsync(absolutePath, contents, cancellationToken, encoding));
public static IAsyncAction AppendLinesAsync(string absolutePath, IEnumerable <string> lines, UwpUnicodeEncoding encoding) => AsyncAction.FromTask(cancellationToken => AppendLinesTaskAsync(absolutePath, lines, cancellationToken, encoding));