Bagikan melalui


StorageFile.GetFileFromPathForUserAsync(User, String) Metode

Definisi

Mendapatkan objek StorageFile berdasarkan jalur absolut dalam sistem file untuk pengguna tertentu.

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)

Parameter

user
User

Pengguna tempat StorageFile dikembalikan.

path
String

Platform::String

winrt::hstring

Jalur file untuk mendapatkan StorageFile yang akan diwakili.

Jika jalur Anda menggunakan garis miring, pastikan Anda menggunakan garis miring terendah (\). Garis miring (/) tidak diterima oleh metode ini.

Mengembalikan

Ketika metode ini selesai, ia mengembalikan file sebagai StorageFile.

Atribut

Persyaratan Windows

Rangkaian perangkat
Windows 10, version 2004 (diperkenalkan dalam 10.0.19041.0)
API contract
Windows.Foundation.UniversalApiContract (diperkenalkan dalam v10.0)

Contoh

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; 
    }    

Keterangan

Metode ini adalah Multi-User Aware (MUA).

Berlaku untuk

Lihat juga