Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9072887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T18:16:50+00:00 2026-06-16T18:16:50+00:00

I am working on a Windows Store app proof of concept that will open

  • 0

I am working on a Windows Store app proof of concept that will open a .zip file and extract the contents to an app-specific Roaming folder. I have looked into several popular libraries to extract the contents only to find that these libraries don’t support Windows Store apps (at least not yet). So, I have decided to go with ZipArchive. I have the following code in a button click handler:

private async void Button_Click_1(object sender, RoutedEventArgs e)
{
    var fileOpenPicker = new FileOpenPicker();
    fileOpenPicker.FileTypeFilter.Add(".zip");
    var openedFile = await fileOpenPicker.PickSingleFileAsync();

    var booksFolder = await Windows.Storage.ApplicationData.Current.RoamingFolder.CreateFolderAsync("Stuff", CreationCollisionOption.OpenIfExists);
    var folder = await booksFolder.CreateFolderAsync(openedFile.Name.Replace(".zip", string.Empty), CreationCollisionOption.ReplaceExisting);

    using (var stream = await openedFile.OpenStreamForReadAsync())
    {
        using (var zip = new ZipArchive(stream, ZipArchiveMode.Read))
        {
            foreach (var entry in zip.Entries)
            {
                using (var entryStream = entry.Open())
                {
                    var file = await folder.CreateFileAsync(entry.Name);
                    using (var decompressedStream = await file.OpenStreamForWriteAsync())
                    {
                        using (var deflateStream = new DeflateStream(entryStream, CompressionMode.Decompress))
                        {
                            await deflateStream.CopyToAsync(decompressedStream, (int)entry.Length);
                        }
                    }
                }
            }
        }
    }
}

However, I get an InvalidDataException on the line

await deflateStream.CopyToAsync(decompressedStream, (int)entry.Length);

Here’s the details of the exception:

System.IO.InvalidDataException was unhandled by user code
  HResult=-2146233087
  Message=Unknown block type. Stream might be corrupted.
  Source=System
  StackTrace:
       at System.IO.Compression.DeflateStream.EndRead(IAsyncResult asyncResult)
       at System.IO.Stream.<BeginEndReadAsync>b__e(Stream stream, IAsyncResult asyncResult)
       at System.Threading.Tasks.TaskFactory`1.FromAsyncTrimPromise`1.Complete(TInstance thisRef, Func`3 endMethod, IAsyncResult asyncResult, Boolean requiresSynchronization)
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.IO.Stream.<CopyToAsyncInternal>d__2.MoveNext()
    --- End of stack trace from previous location where exception was thrown ---
       at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
       at System.Runtime.CompilerServices.TaskAwaiter.GetResult()
       at POC.MoviePlayer.GroupedItemsPage.<Button_Click_1>d__4.MoveNext() in c:\Users\Brent\Documents\Visual Studio 2012\Projects\POC.MoviePlayer\POC.MoviePlayer\GroupedItemsPage.xaml.cs:line 108
  InnerException: 

The .zip file I am trying to import was created with Windows Explorer’s Send To Compressed (Zipped) Folder option. I have also tried to create a .zip file in code, using ZipArchive, but I get more exceptions with that code too. Since that isn’t my ideal use case anyway, I won’t include my code to create the .zip unless it turns out to be useful to somebody.

I am hoping somebody can either see the error of my ways in the code above or provide a link to a solid library to work with zip files that is preferably open source. This frustrated developer would be very grateful for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T18:16:51+00:00Added an answer on June 16, 2026 at 6:16 pm

    You don’t have to decompress the result of entry.Open(). It is already decompressed.

    You could also use ZipFileExtensions.ExtractToDirectory (http://msdn.microsoft.com/en-us/library/system.io.compression.zipfileextensions.extracttodirectory.aspx) to simplify your code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a multi-platform app (Mono) that will store text in a
I'm new to C# and am working on a Windows Store App that lets
I have a windows store app and reviewer indicated that app not working (crashing).
Working on an html5 app for a touchscreen windows xp computer that will be
Recently I started building my own big Windows 8 Store App. Working on UI
We are working on a C# Xaml-based Windows Store app. We have integrated bing
Strange one when working in XAML for Windows RT (windows store app) today, when
I am developing a windows store app that allows a User to place points
I'm building a Windows Store App that uses a GridView to show a list
I am currently working on a Windows 8 app which needs to store some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.