StorageFolder.GetFileAsync(String) 메서드

정의

현재 폴더에서 지정된 이름의 파일을 가져옵니다.

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)

매개 변수

name
String

Platform::String

winrt::hstring

가져올 파일의 이름(또는 현재 폴더에 상대적인 경로)입니다.

반환

이 메서드가 성공적으로 완료되면 지정된 파일을 나타내는 StorageFile 을 반환합니다.

구현

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

예외

지정된 파일이 없는 경우 이름 값을 확인 합니다.

지정된 파일에 액세스할 수 있는 권한이 없습니다. 자세한 내용은 파일 액세스 권한을 참조하세요.

경로는 Uri 형식(예: /image.jpg)일 수 없습니다. 이름 값을 확인 합니다.

예제

다음 예제에서는 GetFileAsync 메서드를 호출하여 현재 폴더에서 파일을 가져오는 방법을 보여줍니다. 또한 이 예제에서는 상대 경로를 제공하여 현재 폴더의 하위 폴더에서 파일을 가져오는 방법도 보여줍니다.

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

설명

파일 또는 폴더의 항목을 얻으려면 GetItemAsync 메서드를 호출합니다.

적용 대상

추가 정보