How do I trap an error when OneDrive image renders file.OpenAsync error -
in project try give users option select images personal libraries. nothing special such.
this goes when user selects desired image local imagelibrary. when images selected onedrive, error occurs, , i'm not able trap error. source of error seems in file.openasync method.
it seems there may relation size of selected image, cannot tell, i'm not able catch error.
here's codesnippet (it's taken xaml image sdk samples in fact)
dim picker new fileopenpicker {.viewmode = pickerviewmode.thumbnail, .suggestedstartlocation = pickerlocationid.pictureslibrary} 'picker.suggestedstartlocation = pickerlocationid.pictureslibrary picker.filetypefilter.add(".png") picker.filetypefilter.add(".jpeg") picker.filetypefilter.add(".jpg") picker.filetypefilter.add(".bmp") dim wbitmap new writablebitmap(200,200) dim file storagefile = await picker.picksinglefileasync() ' ensure file selected if file isnot nothing try ' set source of writeablebitmap image stream using filestream irandomaccessstream = await file.openasync(windows.storage.fileaccessmode.read) await wbitmap.setsourceasync(filestream) wbitmap.invalidate() vwimage.source = wbitmap end using catch e1 taskcanceledexception ' async action set writeablebitmap's source may canceled if user clicks button repeatedly end try end if
as can see, there try-catch in place, nonetheless non-trapped error pops up, , stepping through, can detect happens in line
await file.openasync(windows.storage.fileaccessmode.read)
now question is: how catch error? right line above source of error? , if not so: , how overcome?
after lot of experimenting, think found solutoion.
when storgefile selected used source image, it wise check storagefile.attributes.
files selected carry attributes value. in case of file onedrive, attributes value 544 (the value when combining archive , locallyincomplete. file has downloaded first, , available use.
this explained here: link msdn documentation on storagefile.attributes
Comments
Post a Comment