Windows phone 8 如何从url下载zip文件并在windows phone 8上解压缩。zip文件包含来自服务器的压缩sqlite文件

Windows phone 8 如何从url下载zip文件并在windows phone 8上解压缩。zip文件包含来自服务器的压缩sqlite文件,windows-phone-8,zip,Windows Phone 8,Zip,我无法使用DownloadDataAsync方法。唯一的选项是DownloadStringAsync方法。如何使用此方法下载zip文件。(我是windows phone 8应用程序开发新手)您必须使用DownloadStringAsync方法吗?否则,您可以检查以下各项: 要从url下载zip文件,首先需要将zip文件存储到独立存储中,然后根据需要提取并读取文件 我只是想分享一下对我有效的解决方案。 我创建了一个对给定url的web请求,并将gzip文件下载到独立的存储文件中。现在下载后,

我无法使用DownloadDataAsync方法。唯一的选项是DownloadStringAsync方法。如何使用此方法下载zip文件。(我是windows phone 8应用程序开发新手)

您必须使用DownloadStringAsync方法吗?否则,您可以检查以下各项:


要从url下载zip文件,首先需要将zip文件存储到独立存储中,然后根据需要提取并读取文件


我只是想分享一下对我有效的解决方案。 我创建了一个对给定url的web请求,并将gzip文件下载到独立的存储文件中。现在下载后,我创建了一个目标文件流,并使用GZipStream的WriteByte方法将压缩的gzip流文件从源文件存储到目标文件。现在我们得到了未压缩的文件

注意:-可以从NuGet manager将GZipStream添加到Visual studio

下面是我用来下载和提取GZip文件的代码片段

公共异步任务下载ZipFile(Uri文件地址,字符串文件名) { 尝试 {

            WebRequest request = WebRequest.Create(fileAdress);
            if (request != null)
            {
                WebResponse webResponse = await request.GetResponseAsync();
                if (webResponse.ContentLength != 0)
                {
                    using (Stream response = webResponse.GetResponseStream())
                    {
                        if (response.Length != 0)
                        {
                            using (IsolatedStorageFile isolatedStorage = IsolatedStorageFile.GetUserStoreForApplication())
                            {
                                if (isolatedStorage.FileExists(fileName))
                                    isolatedStorage.DeleteFile(fileName);
                                using (IsolatedStorageFileStream file = isolatedStorage.CreateFile(fileName))
                                {
                                    const int BUFFER_SIZE = 100 * 1024;
                                    byte[] buf = new byte[BUFFER_SIZE];
                                    int bytesread;
                                    while ((bytesread = await response.ReadAsync(buf, 0, BUFFER_SIZE)) > 0)
                                    {
                                        file.Write(buf, 0, bytesread);
                                    }
                                    file.Close();

                                    FileStream sourceFileStream = File.OpenRead(file.Name);
                                    FileStream destFileStream = File.Create(AppResources.OpenZipFileName);

                                    GZipStream decompressingStream = new GZipStream(sourceFileStream, CompressionMode.Decompress);
                                    int byteRead;
                                    while ((byteRead = decompressingStream.ReadByte()) != -1)
                                    {
                                        destFileStream.WriteByte((byte)byteRead);
                                    }
                                    decompressingStream.Close();
                                    sourceFileStream.Close();
                                    destFileStream.Close();
                                    PhoneApplicationService.Current.State["DestinationFilePath"] = destFileStream.Name;
                                }
                            }
                            FileDownload = true;
                        }
                    }
                }
            }

            if (FileDownload == true)
            {
                return DownloadStatus.Ok;
            }
            else
            {
                return DownloadStatus.Other;
            }
        }

        catch (Exception exc)
        {
            return DownloadStatus.Other;
        }

    }