StorageFile.GetFileFromPathForUserAsync(User, String) Methode

Definition

Ruft ein StorageFile-Objekt basierend auf einem absoluten Pfad im Dateisystem für einen bestimmten Benutzer ab.

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

Der Benutzer, für den die StorageFile zurückgegeben wird.

path
String

Platform::String

winrt::hstring

Der Pfad der Datei, die eine StorageFile-Datei darstellen soll.

Wenn Ihr Pfad Schrägstriche verwendet, stellen Sie sicher, dass Sie umgekehrte Schrägstriche (\) verwenden. Schrägstriche (/) werden von dieser Methode nicht akzeptiert.

Gibt zurück

Wenn diese Methode abgeschlossen ist, wird die Datei als StorageFile zurückgegeben.

Attribute

Windows-Anforderungen

Gerätefamilie
Windows 10, version 2004 (eingeführt in 10.0.19041.0)
API contract
Windows.Foundation.UniversalApiContract (eingeführt in v10.0)

Beispiele

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

Hinweise

Diese Methode ist Multi-User Aware (MUA).

Gilt für:

Weitere Informationen