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

Applies to Windows and Windows Phone

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

Any object that implements the IStorageFile interface may be passed to this method through the file parameter.

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

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]

Namespace

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

Metadata

Windows.winmd

See also

FileIO
ReadTextAsync(IStorageFile, UnicodeEncoding)

 

 

Show:
© 2014 Microsoft