Read All Text from Textfile with Encoding in Windows RT

Posted by jdanforth on ASP.net Weblogs See other posts from ASP.net Weblogs or by jdanforth
Published on Wed, 21 Nov 2012 14:53:52 GMT Indexed on 2012/11/21 17:00 UTC
Read the original article Hit count: 324

Filed under:
|
|

A simple extension for reading all text from a text file in WinRT with a specific encoding, made as an extension to StorageFile:

public static class StorageFileExtensions
{
    async public static Task<string> ReadAllTextAsync(this StorageFile storageFile)
    {
        var buffer = await FileIO.ReadBufferAsync(storageFile);
        var fileData = buffer.ToArray();
        var encoding = Encoding.GetEncoding("Windows-1252");
        var text = encoding.GetString(fileData, 0, fileData.Length);
        return text;
    }
}

© ASP.net Weblogs or respective owner

Related posts about c#

Related posts about winrt