Decompress the zip package in Windows Phone 7

Source: Internet
Author: User

In the current project, you need to download the zip package from the server and decompress the package to obtain the files in it. First, record the files and give them some help.

First get sharpziplib. windowsphone7.dll from http://slsharpziplib.codeplex.com/

Add reference

<Phone: phoneapplicationpage
X: class = "phoneapp4.mainpage"
Xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
Xmlns: Phone = "CLR-namespace: Microsoft. Phone. controls; Assembly = Microsoft. Phone"
Xmlns: shell = "CLR-namespace: Microsoft. Phone. Shell; Assembly = Microsoft. Phone"
Xmlns: D = "http://schemas.microsoft.com/expression/blend/2008"
Xmlns: MC = "http://schemas.openxmlformats.org/markup-compatibility/2006"
MC: ignorable = "D" D: designwidth = "480" D: designheight = "768"
Fontfamily = "{staticresource phonefontfamilynormal }"
Xmlns: My = "CLR-namespace: phoneapp4"
Fontsize = "{staticresource phonefontsizenormal }"
Foreground = "{staticresource phoneforegroundbrush }"
Supportedorientations = "portrait" orientation = "portrait"
Shell: systemtray. isvisible = "true">

<Grid X: Name = "layoutroot" background = "Transparent">
<Image Height = "347" horizontalalignment = "Left" margin =, 270 "name =" image1 "stretch =" fill "verticalignment =" TOP "width =" "/>
<Button content = "Download" Height = "72" horizontalalignment = "Left" margin = "38,432," X: name = "btnload" verticalalignment = "TOP" width = "203" Click = "btnload_click"/>
<My: progressbarwithtext X: Name = "progressbarwithtext" text = "loading..." verticalignment = "TOP" foreground = "{staticresource phoneaccentbrush}"/>
</GRID>
</Phone: phoneapplicationpage>

Background code:

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. net;
Using system. windows;
Using system. Windows. controls;
Using system. Windows. documents;
Using system. Windows. input;
Using system. Windows. Media;
Using system. Windows. Media. animation;
Using system. Windows. shapes;
Using Microsoft. Phone. controls;
Using system. net. networkinformation;
Using icsharpcode. sharpziplib. Zip;
Using system. Io. isolatedstorage;
Using system. IO;

Namespace phoneapp4
{
Public partial class mainpage: phoneapplicationpage
{
// Constructor
Public mainpage ()
{
Initializecomponent ();
}

Private void btnload_click (Object sender, routedeventargs E)
{
Button BTN = sender as button;
If (networkinterface. getisnetworkavailable ())
{
BTN. isenabled = false;
WebClient client = new WebClient ();
Progressbarwithtext. showprogress = true;
Client. openreadasync (New uri ("http://files.cnblogs.com/youhui/2012-04/20120405.zip", urikind. Absolute ));
Client. openreadcompleted + = (a, B) =>
{
// Decompress the downloaded zip package
If (null = B. Error &&! B. cancelled)
{
Using (zipinputstream = new zipinputstream (B. Result ))
{
Zipentry;
Byte [] DATA = new byte [2048];
Int size = 2048;
While (zipentry = zipinputstream. getnextentry ())! = NULL)
{
If (zipentry! = NULL)
{
String fname = zipentry. Name;
If (fname! = String. Empty & fname. Contains (". jpg "))
{
Isolatedstoragefile ISF = isolatedstoragefile. getuserstoreforapplication ();
String Path = "Download ";
If (! Directory. exists (PATH ))
{
ISF. createdirectory (PATH );
}
Using (isolatedstoragefilestream filestream = new isolatedstoragefilestream (system. io. path. combine (path + "\", fname. substring (fname. lastindexof ("/") + 1, fname. length-fname. lastindexof ("/")-1), filemode. openorcreate, ISF ))
{
While (true)
{
Size = zipinputstream. Read (data, 0, Data. Length );
If (size <= 0)
Break;
Filestream. Write (data, 0, size );
}
}
}
}
}
}
BTN. content = "downloaded ";
MessageBox. Show ("download completed ");
}
Progressbarwithtext. showprogress = false;
};
}
Else
{
MessageBox. Show ("the current device has no network connection! ");
}
}
}
}

Run and click the Download button:

Use isostorespy to check whether the simulator has been successfully downloaded.

OK.

 

Related Article

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.