c# - Cannot cast IStorageItem to StorageFile -
the following code not compile because isoftype not accepted method on item. documentation states:
when method completes successfully, returns istorageitem represents specified file or folder. if specified file or folder not found, method returns null instead of raising exception.
to work returned item, call isoftype method of istorageitem interface determine whether item file or folder. cast item storagefolder or storagefile.
can me please?
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 storagefile); existingdata = true; } existingdata = false; }
thanks... robert
you missing await
keyword await result of async method - in case should write this:
var item = await folder.trygetitemasync(filename);
thanks item
of type istorageitem
whereas in code of type iasyncoperation<istorageitem>
.
by convention, async methods have async
suffix , need await result inspect it.
tip:
in ides when hover mouse on var
keyword, type of variable displayed - makes easier find error.
Comments
Post a Comment