Bagikan melalui


FileRevocationManager.GetStatusAsync(IStorageItem) Metode

Definisi

Catatan

Mulai Juli 2022, Microsoft menghentikan Windows Information Protection (WIP) dan API yang mendukung WIP. Microsoft akan terus mendukung WIP pada versi Windows yang didukung. Versi baru Windows tidak akan menyertakan kemampuan baru untuk WIP, dan tidak akan didukung di versi Windows yang akan datang. Untuk informasi selengkapnya, lihat Mengumumkan matahari terbenam Windows Information Protection.

Untuk kebutuhan perlindungan data Anda, Microsoft menyarankan agar Anda menggunakan Perlindungan Informasi Microsoft Purview dan Pencegahan Kehilangan Data Microsoft Purview. Purview menyederhanakan pengaturan konfigurasi dan menyediakan serangkaian kemampuan tingkat lanjut.

Catatan

FileRevocationManager mungkin tidak tersedia untuk rilis setelah Windows 10. Sebagai gantinya, gunakan FileProtectionManager.

Mendapatkan status perlindungan penghapusan selektif untuk file atau folder.

public:
 static IAsyncOperation<FileProtectionStatus> ^ GetStatusAsync(IStorageItem ^ storageItem);
/// [Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, Windows.Security.EnterpriseData.EnterpriseDataContract)]
/// [Windows.Foundation.Metadata.RemoteAsync]
 static IAsyncOperation<FileProtectionStatus> GetStatusAsync(IStorageItem const& storageItem);
/// [Windows.Foundation.Metadata.RemoteAsync]
/// [Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Security.EnterpriseData.EnterpriseDataContract")]
 static IAsyncOperation<FileProtectionStatus> GetStatusAsync(IStorageItem const& storageItem);
[Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, typeof(Windows.Security.EnterpriseData.EnterpriseDataContract))]
[Windows.Foundation.Metadata.RemoteAsync]
public static IAsyncOperation<FileProtectionStatus> GetStatusAsync(IStorageItem storageItem);
[Windows.Foundation.Metadata.RemoteAsync]
[Windows.Foundation.Metadata.Deprecated("FileRevocationManager might be unavailable after Windows 10. Instead, use FileProtectionManager.", Windows.Foundation.Metadata.DeprecationType.Deprecate, 65536, "Windows.Security.EnterpriseData.EnterpriseDataContract")]
public static IAsyncOperation<FileProtectionStatus> GetStatusAsync(IStorageItem storageItem);
function getStatusAsync(storageItem)
Public Shared Function GetStatusAsync (storageItem As IStorageItem) As IAsyncOperation(Of FileProtectionStatus)

Parameter

storageItem
IStorageItem

File atau folder untuk mendapatkan status perlindungan penghapusan selektif.

Mengembalikan

Operasi ainkron yang mengambil status perlindungan penghapusan selektif untuk storageItem.

Atribut

Keterangan

Anda dapat menggunakan metode GetStatusAsync untuk menentukan status perlindungan Penghapusan Selektif file atau folder. Ini akan memberi tahu Anda apakah file dilindungi atau tidak, jika file dilindungi oleh pengguna lain di komputer, dan sebagainya. Penggunaan umum metode GetStatusAsync adalah menentukan kapan file yang dilindungi harus dihapus. Misalnya, ketika file yang dilindungi dicabut, upaya untuk mengakses konten file akan menghasilkan pengecualian "Akses ditolak". Ketika Anda menemukan pengecualian itu, Anda dapat menggunakan metode GetStatusAsync untuk menentukan apakah file telah dicabut oleh Penghapusan Selektif lalu menghapus file jika ada, seperti yang ditunjukkan dalam contoh berikut.

ApplicationData appRootFolder = ApplicationData.Current;
string enterpriseIdentity = "example.com";
int AccessDeniedHResult = -2147024891;  // Access Denied (0x80070005)
private async Task<IRandomAccessStream> GetFileContents(string filePath)
{
    IRandomAccessStream stream = null;
    StorageFile file = null;

    try
    {
        file = await StorageFile.GetFileFromPathAsync(filePath);
        stream = await file.OpenReadAsync();
    }
    catch (UnauthorizedAccessException e)
    {
        if (e.HResult == AccessDeniedHResult)
        {
            // Delete file if it has been revoked.
            SelectiveWipeCleanup(file);
        }

        return null;
    }

    return stream;
}

// Delete items revoked by Selective Wipe.
private async void SelectiveWipeCleanup(StorageFile file)
{
    var status = await Windows.Security.EnterpriseData.FileRevocationManager.GetStatusAsync(file);
    if (status == Windows.Security.EnterpriseData.FileProtectionStatus.Revoked)
    {
        await file.DeleteAsync();
    }
}

Berlaku untuk

Lihat juga