locked
Unzipping downloaded .zip file WinRT RRS feed

  • Question

  • Hello,

    Currently I have a WinRT component that downloads a file (In this case a zip file) to the local local directory and tries to unzip the file using the ZipArchive class.

    When creating a new ZipArchive Object I get the following error:  "Central Directory corrupt."

    The code that leads up to the error is the following:

    var folder = ApplicationData.Current.LocalFolder;
                    var file = await folder.GetFileAsync(strZipFile);
    
                    using (var zipStream = await file.OpenStreamForReadAsync())
                    {
                        using (MemoryStream zipMemoryStream = new MemoryStream((int)zipStream.Length))
                        {
                            await zipStream.CopyToAsync(zipMemoryStream);
                            try
                            {
                                using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Read))
                                {}
                            }catch(Exception){}
                         }
                     }

    It always fails on: 

    using (var archive = new ZipArchive(zipStream, ZipArchiveMode.Read))

    With the error above, Is there something different that needs to be done when downloading a zip file as compared to creating a zip file?

    Thursday, September 5, 2013 11:21 PM

Answers

  • Check out my article Archive Multiple Files In Zip & Extract Zip Archive on CodeProject
    • Proposed as answer by Xyroid Friday, September 6, 2013 9:08 AM
    • Marked as answer by Jamles HezModerator Thursday, September 12, 2013 9:08 AM
    Friday, September 6, 2013 9:08 AM
  • Hi obece,

    It seems your code are totally correct, I tested it and everything just works fine, there is no exception fires and I can't find any mistake from your code.

    I'm wondering if the issue is on your zip file, so try to run the code with another Zip file to see if the same issue happens, and if it's possible, send us a copy of your zip for a better support.

    Best Regards, 

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 9, 2013 11:44 AM
    Moderator

All replies

  • Check out my article Archive Multiple Files In Zip & Extract Zip Archive on CodeProject
    • Proposed as answer by Xyroid Friday, September 6, 2013 9:08 AM
    • Marked as answer by Jamles HezModerator Thursday, September 12, 2013 9:08 AM
    Friday, September 6, 2013 9:08 AM
  • So whether i use your solution or the current one that I have, I still get the "Central Directory Corrupt" Exception.

    I did notice that at OpenStreamForReadAsync()

    when I try to open the file, the size of the file is 0, i did double check to make sure that the correct zip is downloaded and that the size verified was what it was supposed to be, any ideas of what this could be? 
    Friday, September 6, 2013 8:58 PM
  • Hi obece,

    It seems your code are totally correct, I tested it and everything just works fine, there is no exception fires and I can't find any mistake from your code.

    I'm wondering if the issue is on your zip file, so try to run the code with another Zip file to see if the same issue happens, and if it's possible, send us a copy of your zip for a better support.

    Best Regards, 

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, September 9, 2013 11:44 AM
    Moderator