StorageFolder.GetFolderFromPathAsync(String) StorageFolder.GetFolderFromPathAsync(String) StorageFolder.GetFolderFromPathAsync(String) StorageFolder.GetFolderFromPathAsync(String) 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)
static IAsyncOperation<StorageFolder> GetFolderFromPathAsync(winrt::hstring path) const;
public static IAsyncOperation<StorageFolder> GetFolderFromPathAsync(String path)
Public Shared Function GetFolderFromPathAsync(path As String) As IAsyncOperation(Of StorageFolder)
Windows.Storage.StorageFolder.getFolderFromPathAsync(path).done( /* Your success and error handlers */ );

Parameters

path
String String String

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

Returns

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

Exceptions

FileNotFoundException FileNotFoundException FileNotFoundException

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

UnauthorizedAccessException UnauthorizedAccessException UnauthorizedAccessException

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

ArgumentException ArgumentException ArgumentException

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());
});
// Get the path to the app's Assets folder.
var root = Windows.ApplicationModel.Package.current.installedLocation.path;
var path = root + "\\Assets";

// Get the folder object that corresponds to
// this absolute path in the file system.
var StorageFolder = Windows.Storage.StorageFolder;
var folderPromise = StorageFolder.getFolderFromPathAsync(path);
folderPromise.done(function getFolderSuccess(folder) {
});

See also