StorageFolder.GetFolderFromPathForUserAsync(User, String) 方法

定义

根据给定用户的文件系统中的绝对路径获取 StorageFolder

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

参数

user
User

为其返回 StorageFolder 的用户。

path
String

Platform::String

winrt::hstring

文件系统中的绝对路径 (不是要获取的文件夹的 Uri) 。

返回

此方法成功完成后,将返回一个 StorageFolder ,表示用户的指定文件夹。

属性

Windows 要求

设备系列
Windows 10, version 2004 (在 10.0.19041.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v10.0 中引入)

示例

async Task<StorageFolder> GetStorageFolderAsync(User user, string path) {     
    // It is possible the folder no longer exists     
    // or permissions were changed so that the     
    // app no longer has access to the path.     
    try     
    {         
        return await StorageFolder.GetFolderFromPathForUserAsync(user, path);     
    }     
    catch( System.IO.IOException ex )    
    {         
        // File, or path not found I/O Exceptions can happen  
        // notify user or implement fallback, etc...         
        string message = ex.Message;         
        return null;     
    }     
    catch(System.UnauthorizedAccessException ex)     
    {         
        // Access denied - notify user or implement fallback, etc...         
        string message = ex.Message;         
        return null;
    }

注解

此方法是多用户感知 (MUA) 。

适用于

另请参阅