StorageFolder.GetItemAsync(String) 메서드

정의

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

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

매개 변수

name
String

Platform::String

winrt::hstring

가져올 파일 또는 폴더의 이름(또는 현재 폴더를 기준으로 하는 경로)입니다.

반환

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

반환된 항목을 사용하려면 IStorageItem 인터페이스의 IsOfType 메서드를 호출하여 항목이 파일인지 폴더인지 확인합니다. 그런 다음, 항목을 StorageFolder 또는 StorageFile으로 캐스팅합니다.

구현

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

예외

지정된 항목이 없습니다. 이름 값을 확인 합니다.

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

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

예제

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

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.
string name = "AppxManifest.xml";
StorageFile manifestFile = (StorageFile)await appFolder.GetItemAsync(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 = (StorageFile)await appFolder.GetItemAsync(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.GetItemAsync(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->GetItemAsync(name)).then([=](IStorageItem^ manifest){
  //Do something with the manifest file  
});

설명

IStorageItem 인터페이스의 IsOfType 메서드를 호출하여 반환된 항목이 파일인지 폴더인지 확인합니다.

반환 값을 캐스팅하지 않고 특정 파일을 얻으려면 GetFileAsync 메서드를 호출합니다. 반환 값을 캐스팅하지 않고 특정 폴더를 얻으려면 GetFolderAsync 메서드를 호출합니다.

FileNotFoundException을 처리할 필요 없이 이름으로 파일 또는 폴더를 얻거나 파일 또는 폴더가 있는지 검사 하려면 TryGetItemAsync 메서드를 호출합니다.

적용 대상

추가 정보