windows phone 8.1 - How to read data files included in the app -
for programme have include huge index , info files in programme bundle. because universal app, have included these files in folder named "data" within "shared" project.
now seek read:
storagefile file = await applicationdata.current.localfolder.getfileasync("data/"+filename); stream stream = (await file.openreadasync()).asstreamforread(); binaryreader reader = new binaryreader(stream); windows.storage.fileproperties.basicproperties x = await file.getbasicpropertiesasync();
i system.argumentexception "mscorlib.ni.dll" @ first line. what's wrong?
if can help me , file, want find filesize. hope, can find info within fileproperties (last line of code).
then want set filepointer within file , read defined number of binary data. can without reading whole file in memory?
what trying access localfolder, not same package.current.installedlocation.
if want access files included package, can illustration - by using uri schemes:
class="lang-cs prettyprint-override">storagefile file = await storagefile.getfilefromapplicationuriasync(new uri(@"ms-appx:///data/"+filename)); using (stream stream = (await file.openreadasync()).asstreamforread()) using (binaryreader reader = new binaryreader(stream)) { windows.storage.fileproperties.basicproperties x = await file.getbasicpropertiesasync(); }
or - getting file package, can access storagefolder - pay attending here utilize right slashes (as may source of exception):
class="lang-cs prettyprint-override">storagefile file = await windows.applicationmodel.package.current.installedlocation.getfileasync(@"data\" + filename); using (stream stream = (await file.openreadasync()).asstreamforread()) using (binaryreader reader = new binaryreader(stream)) { windows.storage.fileproperties.basicproperties x = await file.getbasicpropertiesasync(); }
note i've set stream , binaryreader using, idisposable
, it's suitable release resources no longer needed.
note when shared project has name mysharedproject, have modify path of above uri:
class="lang-cs prettyprint-override">storagefile file = await storagefile.getfilefromapplicationuriasync(new uri(@"ms-appx:///mysharedproject/data/"+filename));
or obtain suitable storagefolder:
class="lang-cs prettyprint-override">storagefile file = await windows.applicationmodel.package.current.installedlocation.getfileasync(@"mysharedproject\data\" + filename);
one remark after discussion:
when add together file .txt extension project, build action default set content. when add together file .idx extension, i've checked, build action set none default. include files in package, alter them content.
windows-phone-8.1 win-universal-app
No comments:
Post a Comment