c# - Downloading a file in Windows store app -


i having trouble downloading files through windows store app. here method downloading:

private static async void downloadimage()     {         httpclient client = new httpclient();          httpresponsemessage message = await client.getasync("http://coolvibe.com/wp-content/uploads/2010/05/scifiwallpaper1.jpg");          storagefolder myfolder = windows.storage.applicationdata.current.localfolder;         storagefile samplefile = myfolder.createfileasync("image.jpg", creationcollisionoption.replaceexisting).getresults();// line throws exception         byte[] file = await message.content.readasbytearrayasync();          await fileio.writebytesasync(samplefile, file);         var files = await myfolder.getfilesasync();      } 

on marked line exception:

an exception of type 'system.invalidoperationexception' occurred in liststalkerwin8.exe not handled in user code  winrt information: method called @ unexpected time.  additional information: method called @ unexpected time. 

what might causing this?

you're calling getresults on iasyncoperation has not yet completed, , not in state can access results (because not exist yet).

in fact, don't need call getresults @ all, need:

storagefile samplefile = await myfolder.createfileasync("image.jpg", creationcollisionoption.replaceexisting); 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -