Metro style app Decompression

Source: Internet
Author: User

This example shows a complete example of Metro ZIP file extraction. First, select the ZIP file to be decompressed and choose Save directory.

Private async void unzipfile (Object sender, routedeventargs e) {fileopenpicker fop = new fileopenpicker (); fop. filetypefilter. add (". zip "); fop. suggestedstartlocation = pickerlocationid. desktop; fop. viewmode = pickerviewmode. list; var zipfile = await fop. picksinglefileasync (); byte [] buffer = windowsruntimebufferextensions. toarray (await windows. storage. fileio. readbufferasync (zipfile); Using (Memor Ystream stream = new memorystream (buffer) {ziparchive = new ziparchive (stream, ziparchivemode. read); folderpicker fp = new folderpicker (); // Add file types to the folderpicker foreach (VAR ziparchiveentry in ziparchive. entries) {If (! Ziparchiveentry. fullname. endswith ("/") {string fileextension = ". "+ RegEx. match (ziparchiveentry. fullname, @ "[^ \.] \ W + $ "). value; If (! FP. filetypefilter. contains (fileextension) FP. filetypefilter. add (fileextension) ;}} FP. suggestedstartlocation = pickerlocationid. desktop; FP. viewmode = pickerviewmode. list; storagefolder unzipfolder = await FP. picksinglefolderasync (); int progress = 0; foreach (VAR ziparchiveentry in ziparchive. entries) {If (! String. isnullorempty (ziparchiveentry. fullname) {If (! Ziparchiveentry. fullname. endswith ("/") {string filename = ziparchiveentry. fullname. replace ("/", "\"); Using (Stream filedata = ziparchiveentry. open () {storagefile newfile = await unzipfolder. createfileasync (filename, creationcollisionoption. replaceexisting); Using (irandomaccessstream newfilestream = await newfile. openasync (fileaccessmode. readwrite) {using (Stream S = newfilestream. asstreamforwrite () {await filedata. copytoasync (s); await S. flushasync () ;}}}} progress ++; progressbar. value = progress * 100/ziparchive. entries. count ;}}}

Source Address

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.