GetFileAsync | getFileAsync method
TOC
Collapse the table of content
Expand the table of content

StorageFolder.GetFileAsync | getFileAsync method

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

Syntax


public:
IAsyncOperation<StorageFile>^ GetFileAsync(
  String^ name
)

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
	StorageFolder^ appFolder = Windows::ApplicationModel::Package::Current->InstalledLocation;

	// Get the app's manifest file from the current folder
	String^ name = "AppxManifest.xml";
	create_task(appFolder->GetFileAsync(name)).then([=](StorageFile^ manifest){
		//Do something with the manifest file 	
	});


Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

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:
© 2016 Microsoft