xamarin.forms - Download a zip file and unzip to internal storage Android Xamarin cross platform app -


is there way download , unzip file remote server using xamarin cross platform application. use pc:storage librray interact files , folders

ifolder rootfolder = filesystem.current.localstorage;         ifolder folder = await rootfolder.createfolderasync("myapproot\\f1",creationcollisionoption.openifexists);         ifile file = await folder.createfileasync("firstfile.txt",             creationcollisionoption.replaceexisting);         await file.writealltextasync("my content"); 

this way created folder f1 inside app root folder , creates files firstfile.txt , write comtent it. how can same zip file ? download zip file , unzip contents folder .

also how can see folders / files created while running application ? isostorespy kind of tools available xamarin android emulator ?

step one, file:

xamarin helps downloading file

here's download task in case link moves/dies:

public static async task<int> createdownloadtask(string urltodownload, iprogress<downloadbytesprogress> progessreporter) { int receivedbytes = 0; int totalbytes = 0; webclient client = new webclient();  using (var stream = await client.openreadtaskasync(urltodownload)) {     byte[] buffer = new byte[4096];     totalbytes = int32.parse(client.responseheaders[httpresponseheader.contentlength]);      (;;)     {         int bytesread = await stream.readasync(buffer, 0, buffer.length);         if (bytesread == 0)         {             await task.yield();             break;         }          receivedbytes += bytesread;         if (progessreporter != null)         {             downloadbytesprogress args = new downloadbytesprogress(urltodownload, receivedbytes, totalbytes);             progessreporter.report(args);         }     } } return receivedbytes; } 

you'll want write data thats being downloaded, add method file handler ,

await zipfile.writeasync(buffer, 0, bytesread); 

then there's unzipping, know i've downloaded microsofts compression nuget before... glancing @ code i've used deflatestream in system.io.compression namespace decompress stuff.

and have handling local file won't mention that.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -