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.