I have a requirement to download a zip(or gzip) file from my cloud server to Windows phone 7 file system and unzip the folder contents in the zip.
With the search I did, I could not find a complete solution for this. I used HttpWebRequest to get the binary content but not sure how to proceed further. The native BinaryReader is not available for windows phone and the HttpWebRequest.Headers for Windows Phone 7 does not seem to have the 'Add' API for specifying the encoding type. I also understand that GZipStream is not available for Windows Phone 7.
Following is the code snippet:
private void btnReadUrl_Click(object sender, RoutedEventArgs e)
{
System.Uri targetUri = new System.Uri("http://cloud/images.gz");
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(targetUri);
request.BeginGetResponse(new AsyncCallback(ReadWebRequestCallback), request);
}
private void ReadWebRequestCallback(IAsyncResult callbackResult)
{
HttpWebRequest myRequest = (HttpWebRequest)callbackResult.AsyncState;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.EndGetResponse(callbackResult);
using (StreamReader httpwebStreamReader = new StreamReader(myResponse.GetResponseStream()))
{
string results = httpwebStreamReader.ReadToEnd();
//TextBlockResults.Text = results; //-- on another thread!
Dispatcher.BeginInvoke(() => txtResult.Text = results);
}
}
I am new to c#, and I an trying to replicate my application from Android to Windows phone.
Could you guide me on what StreamReader is required to read the GZip content, write it into the file system and unzip the content to folders.
Thanks for the replies. I was looking for a library with Apache license or similar so that I can use in my market app. I found this library http://www.sharpgis.net/post/2010/08/25/REALLY-small-unzip-utility-for-Silverlight-e28093-Part-2.aspx and it worked fine.
Further to David's answer. You can get SharpZipLib from NuGet.
Then use code like the following.
You may have to rely on a third-party component such as SharpZipLib
I've developed a HTTP class for WP7 which uses DotNetZip ( http://dotnetzip.codeplex.com/ ).
It can be downloaded here:
https://mytoolkit.codeplex.com/
https://mytoolkit.svn.codeplex.com/svn/Network/
But the
Http
class needs the GZIP classes (found inLibraries
directory) so its best to download the whole source and use the library as DLL.