FileRevocationManager.GetStatusAsync(IStorageItem) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
注意
從 2022 年 7 月開始,Microsoft 即將淘汰 Windows 資訊保護 (WIP) 和支援 WIP 的 API。 Microsoft 將繼續在支援的 Windows 版本上支援 WIP。 新版本的 Windows 不會包含 WIP 的新功能,而且未來版本的 Windows 不支援此功能。 如需詳細資訊,請參閱宣佈 Windows 資訊保護終止。
針對資料保護需求,Microsoft 建議您使用Microsoft Purview 資訊保護和Microsoft Purview 資料外洩防護。 Purview 可簡化組態設定,並提供一組進階功能。
注意
Windows 10之後,FileRevocationManager可能無法用於發行。 請改 用 FileProtectionManager。
取得檔案或資料夾的選擇性抹除保護狀態。
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)
參數
- storageItem
- IStorageItem
要取得選擇性抹除保護狀態的檔案或資料夾。
傳回
擷取 storageItem選擇性抹除保護狀態的非同步作業。
- 屬性
備註
您可以使用 GetStatusAsync 方法來判斷檔案或資料夾的選擇性抹除保護狀態。 這會告訴您檔案是否受到保護,如果檔案受到電腦上的其他使用者保護,依此類故。 GetStatusAsync 方法的常見用法是判斷何時應該刪除受保護的檔案。 例如,撤銷受保護的檔案時,嘗試存取檔案內容會導致「拒絕存取」例外狀況。 當您遇到該例外狀況時,您可以使用 GetStatusAsync 方法來判斷選擇性抹除是否已撤銷檔案,然後刪除檔案,如下列範例所示。
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();
}
}