StorageFolder.GetFileAsync(String) Método

Definición

Obtiene el archivo con el nombre especificado de la carpeta actual.

public:
 virtual IAsyncOperation<StorageFile ^> ^ GetFileAsync(Platform::String ^ name) = GetFileAsync;
/// [Windows.Foundation.Metadata.RemoteAsync]
IAsyncOperation<StorageFile> GetFileAsync(winrt::hstring const& name);
[Windows.Foundation.Metadata.RemoteAsync]
public IAsyncOperation<StorageFile> GetFileAsync(string name);
function getFileAsync(name)
Public Function GetFileAsync (name As String) As IAsyncOperation(Of StorageFile)

Parámetros

name
String

Platform::String

winrt::hstring

Nombre (o ruta de acceso relativa a la carpeta actual) del archivo que se va a obtener.

Devoluciones

Cuando este método se completa correctamente, devuelve un storageFile que representa el archivo especificado.

Implementaciones

M:Windows.Storage.IStorageFolder.GetFileAsync(System.String) M:Windows.Storage.IStorageFolder.GetFileAsync(Platform::String) M:Windows.Storage.IStorageFolder.GetFileAsync(winrt::hstring)
Atributos

Excepciones

El archivo especificado no existe. Compruebe el valor del nombre.

No tiene permiso para acceder al archivo especificado. Para obtener más información, consulte Permisos de acceso a archivos.

La ruta de acceso no puede estar en formato URI (por ejemplo, /image.jpg). Compruebe el valor del nombre.

Ejemplos

En el ejemplo siguiente se muestra cómo obtener un archivo de la carpeta actual llamando al método GetFileAsync. En este ejemplo también se muestra cómo obtener un archivo de una subcarpeta de la carpeta actual proporcionando una ruta de acceso relativa.

using Windows.Storage;
using System.Threading.Tasks;

// 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";
StorageFile manifestFile = await appFolder.GetFileAsync(name);

// Get a file from a subfolder of the current folder
// by providing a relative path.
string image = @"Assets\Logo.scale-100.png";
StorageFile logoImage = await appFolder.GetFileAsync(image);
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the app's installation folder.
    Windows::Storage::StorageFolder appFolder{ Windows::ApplicationModel::Package::Current().InstalledLocation() };

    // Get the app's manifest file from the current folder.
    std::wstring name{ L"AppxManifest.xml" };
    Windows::Storage::StorageFile manifest{ co_await appFolder.GetFileAsync(name) };
    // Do something with the manifest file.
}
// 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  
});

Comentarios

Para obtener un elemento que sea un archivo o una carpeta, llame al método GetItemAsync .

Se aplica a

Consulte también