Unable to use IStorageItem for StorageFile

The following code will not compile because IsOfType is not accepted as a method for the element. The documentation states:

When this method succeeds, it returns an IStorageItem that represents the specified file or folder. If the specified file or folder is not found, this method returns null instead of an exception.

To work with the returned item, call the IsOfType method on the IStorageItem interface to determine if the item is a file or folder. Then move the item to StorageFolder or StorageFile.

private async void RestoreData(string fileName)
    {
        StorageFolder folder = ApplicationData.Current.LocalFolder;
        var item = folder.TryGetItemAsync(fileName);
        if (item == null)
        {
            existingData = false;
        }
        if (item.IsOfType(StorageItemTypes.File))
        {
            await ReadDataAsync(item as StorageFile);
            existingData = true;
        }
        existingData = false;
    }
+4
source share
1 answer

await async - - :

var item = await folder.TryGetItemAsync(fileName);

item IStorageItem, IAsyncOperation<IStorageItem>.

async Async, , .

:

IDE var - .

+3

All Articles