Exemple #1
0
 public void UnZip()
 {
     Shell32.Shell sc = new Shell32.Shell();
     //'UPDATE !!
     //Create directory in which you will unzip your files .
     IO.Directory.CreateDirectory("D:\\extractedFiles");
     //Declare the folder where the files will be extracted
     Shell32.Folder output = sc.NameSpace("D:\\extractedFiles");
     //Declare your input zip file as folder  .
     Shell32.Folder input = sc.NameSpace("d:\\myzip.zip");
     //Extract the files from the zip file using the CopyHere command .
     output.CopyHere(input.Items, 4);
 }
 /// <summary>
 /// 功能:解压zip格式的文件。
 /// </summary>
 /// <param name="zipFilePath">压缩文件路径</param>
 /// <param name="unZipDir">解压文件存放路径,为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹</param>
 /// <param name="err">出错信息</param>
 /// <returns>解压是否成功</returns>
 public static bool UnZipFile(string zipFilePath, string unZipDir, out string err)
 {
     err = "";
     if (zipFilePath.Length == 0)
     {
         err = "压缩文件不能为空!";
         return(false);
     }
     else if (!zipFilePath.EndsWith(".zip"))
     {
         err = "文件格式不正确!";
         return(false);
     }
     else if (!System.IO.File.Exists(zipFilePath))
     {
         err = "压缩文件不存在!";
         return(false);
     }
     //解压文件夹为空时默认与压缩文件同一级目录下,跟压缩文件同名的文件夹
     if (unZipDir.Length == 0)
     {
         unZipDir = zipFilePath.Replace(System.IO.Path.GetFileName(zipFilePath), System.IO.Path.GetFileNameWithoutExtension(zipFilePath));
     }
     if (!unZipDir.EndsWith("\\"))
     {
         unZipDir += "\\";
     }
     if (!System.IO.Directory.Exists(unZipDir))
     {
         System.IO.Directory.CreateDirectory(unZipDir);
     }
     try
     {
         Shell32.ShellClass  sc         = new Shell32.ShellClass();
         Shell32.Folder      SrcFolder  = sc.NameSpace(zipFilePath);
         Shell32.Folder      DestFolder = sc.NameSpace(unZipDir);
         Shell32.FolderItems items      = SrcFolder.Items();
         DestFolder.CopyHere(items, 20);
     }
     catch (Exception ex)
     {
         err = ex.Message;
         return(false);
     }
     return(true);
 }//解压结束
Exemple #3
0
    public void Zip()
    {
        //1) Lets create an empty Zip File .
        //The following data represents an empty zip file .

        byte[] startBuffer =
        {
            80,
            75,
            5,
            6,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0,
            0
        };
        // Data for an empty zip file .
        FileIO.FileSystem.WriteAllBytes("d:\\empty.zip", startBuffer, false);

        //We have successfully made the empty zip file .

        //2) Use the Shell32 to zip your files .
        // Declare new shell class
        Shell32.Shell sc = new Shell32.Shell();
        //Declare the folder which contains the files you want to zip .
        Shell32.Folder input = sc.NameSpace("D:\\neededFiles");
        //Declare  your created empty zip file as folder  .
        Shell32.Folder output = sc.NameSpace("D:\\empty.zip");
        //Copy the files into the empty zip file using the CopyHere command .
        output.CopyHere(input.Items, 4);
    }
Exemple #4
0
        public static bool unzipWDIFiles(string zipFile, string destinationFolder)
        {
            try
            {
                //Shell32.Folder SrcFlder = GetShell32NameSpaceFolder(from);
                //Shell32.Folder DestFlder = GetShell32NameSpaceFolder(to);
                //FolderItems items = SrcFlder.Items();

                //Shell shell = new Shell();
                Shell32.Folder archive       = GetShell32NameSpaceFolder(zipFile);
                Shell32.Folder extractFolder = GetShell32NameSpaceFolder(destinationFolder);

                // Copy each item one-by-one
                foreach (Shell32.FolderItem f in archive.Items())
                {
                    extractFolder.CopyHere(f, 20);
                }
                return(true);
            }
            catch (Exception ex)
            {
                return(false);
            }
        }