Extraiga el archivo zip de almacenamiento aislado

I am stuck at this problem - obviously, I am doing something wrong.

First, I download a zip file via WebClient and storing it into IsolatedStorage:

using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) 
{ 
    if (!isf.DirectoryExists("AppData")) isf.CreateDirectory("AppData"); 
    using (StreamWriter sw = new StreamWriter(new IsolatedStorageFileStream("AppData\\" + FileName, FileMode.OpenOrCreate, isf))) 
    { 
        sw.Write(new StreamReader(e.Result).ReadToEnd()); 
    } 
}

Next, I extract one specific file out of the WebClient response (the zip file):

Uri fileUri = new Uri("content.txt", UriKind.Relative); 
StreamResourceInfo info = new StreamResourceInfo(e.Result, null); 
StreamResourceInfo streamInfo = System.Windows.Application.GetResourceStream(info, fileUri); 

This works as expected. Later on, I want to extract the "content.txt" from the zip file in IsolatedStorage with this:

using (IsolatedStorageFileStream isfs = isf.OpenFile("AppData\\" + FileName, FileMode.Open, FileAccess.Read)) 
{ 
    if (myIsolatedStorage.FileExists("AppData\\" + FileName)) 
    { 
        Uri fileUri = new Uri("content.txt", UriKind.Relative); 
        StreamResourceInfo info = new StreamResourceInfo(isfs, null); 
        StreamResourceInfo streamInfo = System.Windows.Application.GetResourceStream(info, fileUri); 
    } 
} 

Although the zip archive can be found, streamInfo is always null. What am I doing wrong?

preguntado el 31 de julio de 12 a las 15:07

Which zip file?and if you do want to read from the IsolatedStoage por qué estás usando StreamResourceInfo en lugar de StreamReader! -

@Anirudha The zip file is located in the isolatedstorage folder: AppData\\" + FileName I am using StreamResourceInfo because it can access compressed zip archives natively. -

1 Respuestas

Unfortunately, unlike the desktop .Net framework, the Windows Phone 7.x framework does not know how to stream from a compressed file. In fact, on Windows Phone you don't have access to the System.IO.Compression namespace at all.

Afortunadamente, el DotNetZip library works fine for WP7 apps. You'll want to use the Compact Framework binary DLL, not the Silverlight one. Visual Studio will complain the library may not be compatible when adding the reference, but it'll work just fine.

Respondido 31 Jul 12, 19:07

I am using this technique to avoid any third party lib: sharpgis.net/post/2009/04/22/… - Jaspe

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.