共用方式為


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) 。

適用於

另請參閱