StorageFolder.GetFolderFromPathAsync(String) Method

Definition

Gets the folder that has the specified absolute path in the file system.

public:
 static IAsyncOperation<StorageFolder ^> ^ GetFolderFromPathAsync(Platform::String ^ path);
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<StorageFolder> GetFolderFromPathAsync(winrt::hstring const& path);
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<StorageFolder> GetFolderFromPathAsync(string path);
function getFolderFromPathAsync(path)
Public Shared Function GetFolderFromPathAsync (path As String) As IAsyncOperation(Of StorageFolder)

Parameters

path
String

Platform::String

winrt::hstring

The absolute path in the file system (not the Uri) of the folder to get.

If your path uses slashes, make sure you use backslashes (\). Forward slashes (/) are not accepted by this method.

Returns

When this method completes successfully, it returns a StorageFolder that represents the specified folder.

Attributes

Exceptions

The specified folder does not exist. Check the value of path.

You don't have permission to access the specified folder. For more information, see File access permissions.

The path cannot be a relative path or a Uri. Check the value of path.

Examples

The following example shows how to get the folder that has the specified absolute path in the file system by calling the GetFolderFromPathAsync method.

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

// Get the path to the app's Assets folder.
string root = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
string path = root + @"\Assets";

// Get the folder object that corresponds to this absolute path in the file system.
StorageFolder folder = await StorageFolder.GetFolderFromPathAsync(path);
IAsyncAction MainPage::ExampleCoroutineAsync()
{
    // Get the path to the app's Assets folder.
    std::wstring path{ Windows::ApplicationModel::Package::Current().InstalledLocation().Path() + L"\\Assets" };

    // Get the folder object that corresponds to this absolute path in the file system.
    Windows::Storage::StorageFolder folder{ co_await Windows::Storage::StorageFolder::GetFolderFromPathAsync(path) };
    ::OutputDebugString(folder.Name().c_str());
}
// Get the path to the app's installation folder.
String^ root = Windows::ApplicationModel::Package::Current->InstalledLocation->Path;

// Get the folder object that corresponds to
// this absolute path in the file system.
create_task(StorageFolder::GetFolderFromPathAsync(root)).then([=](StorageFolder^ folder){
 String^ output = folder->Name;
 OutputDebugString(output->Begin());
});

Applies to

See also