FileIO.ReadTextAsync(IStorageFile) | readTextAsync(IStorageFile) method

0 out of 3 rated this helpful - Rate this topic

Reads the contents of the specified file and returns text.

Syntax


Windows.Storage.FileIO.readTextAsync(file).done( /* Your success and error handlers */ );

Parameters

file

Type: IStorageFile

The file to read.

Return value

Type: IAsyncOperation<String>

When this method completes successfully, it returns the contents of the file as a text string.

Remarks

This method uses the character encoding of the specified file. If you want to specify different encoding, call ReadTextAsync(IStorageFile, UnicodeEncoding) instead.

Examples

The File Access sample shows you how to use readTextAsync(file) to read text from a file, like this:


if (file !== null) {
    Windows.Storage.FileIO.readTextAsync(file).done(function (fileContent) {
        // Process content read from the file
    },
    // Handle errors with an error function
    function (error) {
        // Handle errors encountered during read
    });
}

In the example, file is a local variable that contains a storageFile that represents the file to read.

After readTextAsync completes, the fileContent variable gets the contents of the file as a text string. You can then process the contents as appropriate.

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Namespace

Windows.Storage
Windows::Storage [C++]

Metadata

Windows.winmd

See also

FileIO
ReadTextAsync(IStorageFile, UnicodeEncoding)

 

 

Build date: 2/25/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.