Here are the steps,

Step 1 - Create a simple Windows Project. Click New Project, Visual C#, Windows 8, Windows, then select Blank App (Windows 8.1).

Here you can go through my previous article: Zip Folder and Its Content in Windows Runtime Apps.

app

Step 2 - Let us add a button in MainPage.xaml :
  • A button with the Click event.

    Complete MainPage.xaml:
    1. <Page
    2. x:Class="UnZip.MainPage"
    3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    5. xmlns:local="using:UnZip"
    6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    8. mc:Ignorable="d">
    9. <Grid Background="#FF2077D4">
    10. <Button x:Name="btn_Unzip" Content="Unzip" HorizontalAlignment="Left" Margin="351,270,0,0" VerticalAlignment="Top" Height="83" Width="313" Click="btn_Unzip_Click"/>
    11. </Grid>
    12. </Page>
Step 3 - Let us add a zip file in Assets folder of Solution Explorer. Unzip the contents of the zip folder and save all the files in application local folder.

Note: Make sure the Build Action is set to Content in the Properties of your zip file.

Properties

Step 4 - In the code behind: MainPage.xaml.cs,

Update your code with this:
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.IO.Compression;
  5. using System.Linq;
  6. using System.Runtime.InteropServices.WindowsRuntime;
  7. using Windows.ApplicationModel;
  8. using Windows.Foundation;
  9. using Windows.Foundation.Collections;
  10. using Windows.Storage;
  11. using Windows.UI.Xaml;
  12. using Windows.UI.Xaml.Controls;
  13. using Windows.UI.Xaml.Controls.Primitives;
  14. using Windows.UI.Xaml.Data;
  15. using Windows.UI.Xaml.Input;
  16. using Windows.UI.Xaml.Media;
  17. using Windows.UI.Xaml.Navigation;
  18. namespace UnZip
  19. {
  20. public sealed partial class MainPage : Page
  21. {
  22. public MainPage()
  23. {
  24. this.InitializeComponent();
  25. }
  26. private async void btn_Unzip_Click(object sender, RoutedEventArgs e)
  27. {
  28. try
  29. {
  30. StorageFolder appFolder = ApplicationData.Current.LocalFolder;
  31. var zipFile = await Package.Current.InstalledLocation.GetFileAsync("Assets\\TestZip.zip");
  32. using (var zipFileStream = await zipFile.OpenStreamForReadAsync())
  33. {
  34. using (MemoryStream memoryStream = new MemoryStream((int)zipFileStream.Length))
  35. {
  36. await zipFileStream.CopyToAsync(memoryStream);
  37. using (var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Read))
  38. {
  39. foreach (ZipArchiveEntry zipArchiveEntry in zipArchive.Entries)
  40. {
  41. string[] arrayFolder = zipArchiveEntry.FullName.Split(new string[] { "/" }, StringSplitOptions.None);
  42. string folderName = string.Empty;
  43. for (int i = 0; i < arrayFolder.Length - 1; i++)
  44. {
  45. folderName += "\\" + arrayFolder[i];
  46. }
  47. if (zipArchiveEntry.Name != "")
  48. {
  49. using (Stream fileData = zipArchiveEntry.Open())
  50. {
  51. StorageFile outputFile = await appFolder.CreateFileAsync(folderName + "\\" + zipArchiveEntry.Name, CreationCollisionOption.ReplaceExisting);
  52. using (Stream outputFileStream = await outputFile.OpenStreamForWriteAsync())
  53. {
  54. await fileData.CopyToAsync(outputFileStream);
  55. await outputFileStream.FlushAsync();
  56. }
  57. }
  58. }
  59. else
  60. {
  61. await appFolder.CreateFolderAsync(folderName, CreationCollisionOption.ReplaceExisting);
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. catch (Exception ex)
  69. {
  70. }
  71. }
  72. }
  73. }
Step 5 - Run the application and click the Unzip button. You see the extracted content of zip file inside: This PC, C, Users, [Your User Name] > AppData, Local, Packages, [App package name], then go to LocalState,

local state

That’s it.

You can also get the complete project from GitHub.