pandazx's blog

データ分析など雑多な技術ブログ

C#でzipファイル解凍

src.zipを解凍して、C:\dstフォルダに出力するサンプル。

コンソールアプリケーションのプロジェクトを作成して以下を記述

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Ionic.Zip;

namespace unzipTextBinary
{
  class Program
  {
    static void Main(string[] args)
    {
      string src = "C:\\src.zip";
      string dst = "C:\\dst";

      MemoryStream ms = new MemoryStream();
      StreamWriter sw = new StreamWriter(ms);
      ReadOptions options = new ReadOptions();
      ZipFile zf = ZipFile.Read(src, options);
      zf.ExtractAll(dst);
    }
  }
}

以下を参考
[C#] ZIPファイルを展開、解凍する - DotNetZip を利用

DotNetZipライブラリのIonic.Zip.dllが必要
ライセンスはMicrosoft Public License (Ms-PL)
ダウンロード、設定手順は上記サイトを参考

Ms-PLについては下記が参考になる
マイクロソフトの主要なシェアードソースライセンスに関して « 来栖川電算