Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

StorageFolder.GetFileAsync | getFileAsync method

Applies to Windows and Windows Phone

Gets the file with the specified name from the current folder.

Syntax


storageFolder.getFileAsync(name).done( /* Your success and error handlers */ );

Parameters

name

Type: String [JavaScript] | System.String [.NET] | Platform::String [C++]

The name (or path relative to the current folder) of the file to get.

Return value

Type: IAsyncOperation<StorageFile>

When this method completes successfully, it returns a StorageFile that represents the specified file.

Exceptions

ExceptionCondition
System.IO.FileNotFoundException

The specified file does not exist. Check the value of name.

System.UnauthorizedAccessException

You don't have permission to access the specified file.

System.ArgumentException

The path cannot be in Uri format (for example, /image.jpg). Check the value of name.

Remarks

To get an item that's a file or a folder, call the GetItemAsync method.

Examples

The following example shows how to get a file from the current folder by calling the GetFileAsync method. This example also shows how to get a file from a subfolder of the current folder by providing a relative path.


// Get the app's installation folder.
var appFolder = Windows.ApplicationModel.Package.current.installedLocation;

// Get the app's manifest file from the current folder.
var name = "AppxManifest.xml";
var manifestFilePromise = appFolder.getFileAsync(name);
var logoImagePromise = manifestFilePromise.then(function getFileSuccess(manifestFile) {

    // Get a file from a subfolder of the current folder
    // by providing a relative path.
    var image = "images\\Logo.scale-100.png";
    return appFolder.getFileAsync(image);
});
logoImagePromise.done(function (logoImage) {
    console.log(logoImage.name);
});

Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8

Namespace

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

Metadata

Windows.winmd

See also

StorageFolder
GetItemAsync

 

 

Show:
© 2014 Microsoft