Share via


StorageFile.GetFileFromPathForUserAsync(User, String) Metodo

Definizione

Ottiene un oggetto StorageFile basato su un percorso assoluto nel file system per un determinato utente.

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)

Parametri

user
User

Utente per cui viene restituito StorageFile .

path
String

Platform::String

winrt::hstring

Percorso del file per ottenere un oggetto StorageFile da rappresentare.

Se il percorso usa le barre, assicurarsi di usare le barre rovesciata (\). Le barre (/) non vengono accettate da questo metodo.

Restituisce

Al termine di questo metodo, restituisce il file come StorageFile.

Attributi

Requisiti Windows

Famiglia di dispositivi
Windows 10, version 2004 (è stato introdotto in 10.0.19041.0)
API contract
Windows.Foundation.UniversalApiContract (è stato introdotto in v10.0)

Esempio

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

Commenti

Questo metodo è compatibile con più utenti (MUA).

Si applica a

Vedi anche