c# - UWP . Copy file from FileOpenPicker to localstorage -
fileopenpicker picker = new fileopenpicker(); picker.viewmode = pickerviewmode.thumbnail; picker.suggestedstartlocation = pickerlocationid.computerfolder; picker.filetypefilter.add(".txt");
a user chooses file open. how can store/copy/save that file localstorage for future use, every time app opens, picks automatically file?
after user opens file using fileopenpicker
can "cache" access using storageapplicationpermissions
api.
once have storagefile
want open automatically, can "cache" access using following code:
string token = storageapplicationpermissions.futureaccesslist.add( file );
what string token, can save example in app settings. next time app opened, can retrieve file again using following code:
storagefile file = await storageapplicationpermissions.futureaccesslist.getfileasync(token);
note api has limitation of @ 1000 items stored, if expect more added, have ensure older files removed otherwise not able add new files.
there alternative - storageapplicationpermissions.mostrecentlyusedlist
can use same way futureaccesslist
, has advantage of automatically managing list. can store 25 items, able automatically remove oldest ones when not needed anymore.
also note, apis can cache access not files folders (storagefolder
).
copying file appdata folder
if want create local copy of picked file, can copy local folder of app.
var file = await picker.picksinglefileasync(); if ( file != null ) { await file.copyasync( applicationdata.current.localfolder ); }
Comments
Post a Comment