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)
属性

例外

指定したファイルが存在しません。 name の値を確認 します

指定したファイルにアクセスするためのアクセス許可がありません。 詳細については、「 ファイル アクセス許可」を参照してください。

パスを URI 形式 (/image.jpg など) にすることはできません。 name の値を確認 します

次の例では、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 メソッドを呼び出します。

適用対象

こちらもご覧ください