2016年12月28日 星期三

[研究] [C#] 用 DotNetZip Library v1.9.1.8 解壓縮程式庫

[研究] [C#] 用 DotNetZip Library v1.9.1.8 解壓縮程式庫

2016-12-27

v1.9.1.8 DotNetZip
Jul 11, 2011, Stable
https://dotnetzip.codeplex.com/releases/view/68268
5年多沒有更新了

以 Visual Studio 2015 with Update 開啟 solution 後編譯失敗。



\DotNetZip-src-v1.9.1.8\DotNetZip\Examples\C#\CreateZip\bin\Debug  目錄有 Ionic.Zip.dll 檔案

(下圖)
\DotNetZip-src-v1.9.1.8\DotNetZip\Examples\C#\CreateZip 專案實際測試可以編譯成功和使用

程式碼

// CreateZip.cs
//
// ----------------------------------------------------------------------
// Copyright (c) 2006, 2007, 2008 Microsoft Corporation.  All rights reserved.
//
// This example is released under the Microsoft Permissive License of
// October 2006.  See the license.txt file accompanying this release for
// full details.
//
// ----------------------------------------------------------------------
//
// This simplistic utility gets a list of all the files in the specified directory,
// and zips them into a single archive.  This utility does not recurse through
// the directory tree.
//
// compile with:
//     csc /debug+ /target:exe /R:Ionic.Utils.Zip.dll /out:CreateZip.exe CreateZip.cs
//
//
// Wed, 29 Mar 2006  14:36
//

using System;
using Ionic.Zip;

namespace Ionic.Zip.Examples
{
    public class CreateZip
    {
        private static void Usage()
        {
            Console.WriteLine("usage:\n  CreateZip <ZipFileToCreate> <directory>");
            Environment.Exit(1);
        }

        public static void Main(String[] args)
        {
            if (args.Length != 2) Usage();
            if (!System.IO.Directory.Exists(args[1]))
            {
                Console.WriteLine("The directory does not exist!\n");
                Usage();
            }
            if (System.IO.File.Exists(args[0]))
            {
                Console.WriteLine("That zipfile already exists!\n");
                Usage();
            }
            if (!args[0].EndsWith(".zip"))
            {
                Console.WriteLine("The filename must end with .zip!\n");
                Usage();
            }

            string ZipFileToCreate = args[0];
            string DirectoryToZip = args[1];
            try
            {
                using (ZipFile zip = new ZipFile())
                {
                    // note: this does not recurse directories!
                    String[] filenames = System.IO.Directory.GetFiles(DirectoryToZip);

                    // This is just a sample, provided to illustrate the DotNetZip interface.
                    // This logic does not recurse through sub-directories.
                    // If you are zipping up a directory, you may want to see the AddDirectory() method,
                    // which operates recursively.
                    foreach (String filename in filenames)
                    {
                        Console.WriteLine("Adding {0}...", filename);
                        ZipEntry e= zip.AddFile(filename);
                        e.Comment = "Added by Cheeso's CreateZip utility.";
                    }

                    zip.Comment= String.Format("This zip archive was created by the CreateZip example application on machine '{0}'",
                       System.Net.Dns.GetHostName());

                    zip.Save(ZipFileToCreate);
                }

            }
            catch (System.Exception ex1)
            {
                System.Console.Error.WriteLine("exception: " + ex1);
            }

        }
    }
}

(待續)

沒有留言:

張貼留言