c# - how to copy image from filepiker to app folder windows store apps -
this code of file picker
need copy image user open app folder. 1 can me please
private async void button_click(object sender, routedeventargs e) { if (windows.ui.viewmanagement.applicationview.value != windows.ui.viewmanagement.applicationviewstate.snapped || windows.ui.viewmanagement.applicationview.tryunsnap() == true) { windows.storage.pickers.fileopenpicker openpicker = new windows.storage.pickers.fileopenpicker(); openpicker.suggestedstartlocation = windows.storage.pickers.pickerlocationid.pictureslibrary; openpicker.viewmode = windows.storage.pickers.pickerviewmode.thumbnail; // filter include sample subset of file types. openpicker.filetypefilter.clear(); openpicker.filetypefilter.add(".bmp"); openpicker.filetypefilter.add(".png"); openpicker.filetypefilter.add(".jpeg"); openpicker.filetypefilter.add(".jpg");
// open file picker.
windows.storage.storagefile file = await openpicker.picksinglefileasync(); // file null if user cancels file picker. if (file != null) { // open stream selected file. windows.storage.streams.irandomaccessstream filestream = await file.openasync(windows.storage.fileaccessmode.read);
// set image source selected bitmap.`
windows.ui.xaml.media.imaging.bitmapimage bitmapimage = new windows.ui.xaml.media.imaging.bitmapimage(); bitmapimage.setsource(filestream); img.source = bitmapimage; this.datacontext = file; } } }
thanks
use storagefile.copyasync, is, file.copyasync. first argument destination storagefolder, e.g. windows.storage.applicationdata.current.localfolder if wanted copy appdata; otherwise you'd need create folder or 1 picker separately.
you might, example, have user choose default folder file picker (configured folders). sure save storagefolder in [windows.storage.accesscache][2]
preserve programmatic access future use.