http://niyodiary.cocolog-nifty.com/blog/2009/03/czip-d457.html#.A20090319_1_1
using System.IO; using System.IO.Compression; using System.Runtime.InteropServices; [DllImport("ZIP32J.DLL", CharSet = CharSet.Ansi)] private static extern int Zip( IntPtr hwnd, // ウィンドウハンドル string szCmdLine, // コマンドライン StringBuilder szOutput, // 処理結果文字列 int dwSize); // 引数szOutputの文字列サイズ /// <summary> /// zipファイルに指定したファイルを(上書き)追加 /// </summary> /// <param name="sZipFile">zipファイル</param> /// <param name="oAddFileList">追加するファイル一覧</param> /// <remarks> /// zip32.dll利用 /// 総合アーカイバプロジェクトのDLLが必要 /// http://www.csdinc.co.jp/archiver/lib/zip32j.html /// </remarks> private void AddZipFile(string sZipFile, List<string> oAddFileList) { StringBuilder oCmdLine = new StringBuilder(1024); // コマンドライン文字列 StringBuilder oOutput = new StringBuilder(1024); // ZIP32J.dll出力文字 // コマンド組み立て oCmdLine.AppendFormat("-q -j \"{0}\"", sZipFile); foreach (string sAddFile in oAddFileList) { oCmdLine.AppendFormat(" \"{0}\"", sAddFile); } // 圧縮 int iZipRtn = Zip((IntPtr)0, oCmdLine.ToString(), oOutput, oOutput.Capacity); // 成功判定 if (iZipRtn != 0) { string sMsg = string.Format("ZIP圧縮/解凍処理に失敗:\nエラーコード={0}:\n{1}", iZipRtn, oOutput.ToString()); throw new ApplicationException(sMsg); } } /// <summary> /// zipファイルに指定したファイルを(上書き)追加 /// </summary> /// <param name="sZipFile">zipファイル</param> /// <param name="oAddFileList">追加するファイル一覧</param> /// <remarks> /// System.IO.Compression.ZipFile利用 /// .NET Framework 4.5以上が必要 /// </remarks> /// private void AddZipFile_dotNet(string sZipFile, List<string> oAddFileList) { // zipファイルが存在しない場合、空のzipファイルを作成 if (File.Exists(sZipFile) == false) { ZipFile.Open(sZipFile, ZipArchiveMode.Create).Dispose(); } // zipに、ファイルを(上書き)追加 using (ZipArchive oArchive = ZipFile.Open(sZipFile, ZipArchiveMode.Update)) { foreach (string sAddFile in oAddFileList) { string sEntryName = Path.GetFileName(sAddFile); ZipArchiveEntry oEntry = oArchive.GetEntry(sEntryName); if (oEntry != null) { oEntry.Delete(); } oArchive.CreateEntryFromFile(sAddFile, sEntryName); } } }