StorageFolder.GetFileAsync(String) Metode

Definisi

Mendapatkan file dengan nama yang ditentukan dari folder saat ini.

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)

Parameter

name
String

Platform::String

winrt::hstring

Nama (atau jalur relatif terhadap folder saat ini) dari file yang akan didapatkan.

Mengembalikan

Ketika metode ini berhasil diselesaikan, metode ini mengembalikan StorageFile yang mewakili file yang ditentukan.

Penerapan

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

Pengecualian

File yang ditentukan tidak ada. Periksa nilai nama.

Anda tidak memiliki izin untuk mengakses file yang ditentukan. Untuk informasi selengkapnya, lihat Izin akses file.

Jalur tidak dapat dalam format Uri (misalnya, /image.jpg). Periksa nilai nama.

Contoh

Contoh berikut menunjukkan cara mendapatkan file dari folder saat ini dengan memanggil metode GetFileAsync. Contoh ini juga menunjukkan cara mendapatkan file dari subfolder folder saat ini dengan menyediakan jalur relatif.

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  
});

Keterangan

Untuk mendapatkan item yang merupakan file atau folder, panggil metode GetItemAsync .

Berlaku untuk

Lihat juga