windows 10 - UWP apps accessing files from random location on system -
in uwp there files , permissions restrictions, can acces files directly few folders or can use filepicker access anywhere on system. how can use files picked filepicker , use them anytime again when app runs ? tried use them again path gives permission error. know "futureacceslist" limit 1000 , make app slow if not wrong? . there better way ? or can store storage files link somehow in local sqlite database?
considering method..
public async static task<byte[]> tobytearray(this storagefile file) { byte[] filebytes = null; using (irandomaccessstreamwithcontenttype stream = await file.openreadasync()) { filebytes = new byte[stream.size]; using (datareader reader = new datareader(stream)) { await reader.loadasync((uint)stream.size); reader.readbytes(filebytes); } } return filebytes; }
this class..
public class appfile { public string filename { get; set; } public byte[] bytearray { get; set; } }
and variable
list<appfile> _appfiles = new list<appfile>();
just..
var fileopenpicker = new fileopenpicker(); ireadonlylist<storagefile> files = await fileopenpicker.pickmultiplefilesasync(); foreach (var file in files) { var bytearray = await file.tobytearray(); _appfiles.add(new appfile { filename = file.displayname, bytearray = bytearray }); }
update
using newtonsoft.json; using system.linq; using windows.security.credentials; using windows.storage; namespace your.namespace { public class stateservice { public void savestate<t>(string key, t value) { var localsettings = applicationdata.current.localsettings; localsettings.values[key] = jsonconvert.serializeobject(value); } public t loadstate<t>(string key) { var localsettings = applicationdata.current.localsettings; if (localsettings.values.containskey(key)) return jsonconvert.deserializeobject<t>(((string) localsettings.values[key])); return default(t); } public void removestate(string key) { var localsettings = applicationdata.current.localsettings; if (localsettings.values.containskey(key)) localsettings.values.remove((key)); } public void clear() { applicationdata.current.localsettings.values.clear(); } } }
Comments
Post a Comment