Share via


StorageFile.GetFileFromPathForUserAsync(User, String) 方法

定义

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

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

参数

user
User

为其返回 StorageFile 的用户。

path
String

Platform::String

winrt::hstring

要获取要表示的 StorageFile 的文件的路径。

如果路径使用斜杠,请确保使用反斜杠 (\) 。 此方法不接受 /) (正斜杠。

返回

此方法完成后,它将文件作为 StorageFile 返回。

属性

Windows 要求

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

示例

async Task<StorageFile> GetStorageFileAsync(User user, string path) {     
    // It is possible the file no longer exists     
    // or permissions were changed so that the     
    // app no longer has access to the path.     
    try     
    {         
        return await StorageFile.GetFileFromPathForUserAsync(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) 。

适用于

另请参阅