FileRevocationManager.GetStatusAsync(IStorageItem) Method

Definition

Note

Starting in July 2022, Microsoft is deprecating Windows Information Protection (WIP) and the APIs that support WIP. Microsoft will continue to support WIP on supported versions of Windows. New versions of Windows won't include new capabilities for WIP, and it won't be supported in future versions of Windows. For more information, see Announcing sunset of Windows Information Protection.

For your data protection needs, Microsoft recommends that you use Microsoft Purview Information Protection and Microsoft Purview Data Loss Prevention. Purview simplifies the configuration set-up and provides an advanced set of capabilities.

Note

FileRevocationManager may be unavailable for releases after Windows 10. Instead, use FileProtectionManager.

Gets the selective wipe protection status for a file or 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)

Parameters

storageItem
IStorageItem

The file or folder to get the selective wipe protection status for.

Returns

An aysnchronous operation that retrieves the selective wipe protection status for the storageItem.

Attributes

Remarks

You can use the GetStatusAsync method to determine the Selective Wipe protection status of a file or folder. This will tell you if a file is protected or not, if a file is protected by another user on the computer, and so on. A common use of the GetStatusAsync method is to determine when a protected file should be deleted. For example, when a protected file is revoked, an attempt to access the file contents will result in an "Access is denied" exception. When you encounter that exception, you can use the GetStatusAsync method to determine if the file has been revoked by Selective Wipe and then delete the file if it has, as shown in the following example.

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

Applies to

See also