Expand Minimize

StorageFolder.GetItemAsync | getItemAsync method

Applies to Windows and Windows Phone

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

Syntax


storageFolder.getItemAsync(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 or folder to get.

Return value

Type: IAsyncOperation<IStorageItem>

When this method completes successfully, it returns an IStorageItem that represents the specified file or folder.

To work with the returned item, call the IsOfType method of the IStorageItem interface to determine whether the item is a file or a folder. Then cast the item to a StorageFolder or StorageFile.

Exceptions

ExceptionCondition
System.IO.FileNotFoundException

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

System.UnauthorizedAccessException

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

System.ArgumentException

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

Remarks

Call the IsOfType method of the IStorageItem interface to determine whether the returned item is a file or a folder.

To get a specific file without casting the return value, call the GetFileAsync method. To get a specific folder without casting the return value, call the GetFolderAsync method.

To try to get a file or folder by name, or to check whether a file or folder exists, without the need to handle a FileNotFoundException, call the TryGetItemAsync method.

Examples

The following example shows how to get a single file or folder from the current folder by calling the GetItemAsync method. This example also shows how to get an item 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.
var name = "AppxManifest.xml";
var manifestFilePromise = appFolder.getItemAsync(name);
manifestFilePromise.done(function getItemSuccess(manifestFile) {
});

// Get a file from a subfolder of the current folder
// by providing a relative path.
var image = "Assets\\Logo.scale-100.png";
var logoImagePromise = appFolder.getItemAsync(image);
logoImagePromise.done(function getItemSuccess(logoImage) {
});

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
GetFileAsync
GetFolderAsync
TryGetItemAsync

 

 

Show:
© 2014 Microsoft