locked
ZipArchive not working for Universal App (Windows 8.1 and Windows Phone 8.1)

    Question

  • Hi i have this problem in ZipArchive for my universal app. The code below works fine for the Windows Phone but not for the Windows 8.1 app.

    I can'nt see why this is not working for the Windows 8.1 app, but only for the Windows Phone

    The Exception i get is this: "Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory." when i try to read the entries.

    using (var zipStream = await folder.OpenStreamForReadAsync(filename))
            {
                using (MemoryStream zipMemoryStream = new MemoryStream((int)zipStream.Length))
                {
                    await zipStream.CopyToAsync(zipMemoryStream);
    
                    using (var archive = new ZipArchive(zipMemoryStream, ZipArchiveMode.Read))
                    {
                        try
                        {
                            // THIS CAUSE THE EXCEPTION!!!!
                            foreach (var entry in archive.Entries)
                            {
    
                                if (entry.Name == "")
                                {
                                    // Folder
                                    await CreateRecursiveFolder(folder, entry);
                                }
                                else
                                {
                                    // File
                                    await ExtractFile(folder, entry);
                                }
                            }
    
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.Message);
                            //throw;
                        }
                    }
                }


    Thursday, October 30, 2014 10:57 AM

Answers

  • I ran this code using the following additional:

    FileOpenPicker MyFOP = new FileOpenPicker();
    MyFOP.FileTypeFilter.Add(".zip");
    StorageFile MyZipFile = await MyFOP.PickSingleFileAsync();
    using (var zipStream = await MyZipFile.OpenStreamForReadAsync())
    {
      // Your remaining code here

    It worked fine for me in my Windows 8.1 project.  If you have a project available for review, please post it to OneDrive and paste a link to it here.


    Matt Small - Microsoft Escalation Engineer - Forum Moderator
    If my reply answers your question, please mark this post as answered.

    NOTE: If I ask for code, please provide something that I can drop directly into a project and run (including XAML), or an actual application project. I'm trying to help a lot of people, so I don't have time to figure out weird snippets with undefined objects and unknown namespaces.

    Thursday, October 30, 2014 7:17 PM
    Moderator