当前位置: 首页>>代码示例>>C#>>正文


C# ZipFile.AddItem方法代码示例

本文整理汇总了C#中Ionic.Zip.ZipFile.AddItem方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.AddItem方法的具体用法?C# ZipFile.AddItem怎么用?C# ZipFile.AddItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ionic.Zip.ZipFile的用法示例。


在下文中一共展示了ZipFile.AddItem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateFileToUpload

        static string CreateFileToUpload(IList<string> files)
        {
            if (files == null || files.Count == 0)
            {
                Console.WriteLine("No files were supplied");
                Environment.Exit(1);
            }

            string temporaryFile = Path.GetTempFileName() + ".zip";

            using (var zip = new ZipFile())
            {
                foreach (string file in files)
                {
                    if (File.Exists(file) || Directory.Exists(file))
                    {
                        zip.AddItem(file);
                    }
                    else if (file.Contains("*") || file.Contains("?"))
                    {
                        string parent = Path.GetDirectoryName(file);

                        if (parent == null)
                        {
                            Console.WriteLine("Unabled to find file or folder: {0}", file);
                            Environment.Exit(10);
                        }

                        string wildCard = Path.GetFileName(file);

                        if (wildCard == null)
                        {
                            Console.WriteLine("Unabled to find file or folder: {0}", file);
                            Environment.Exit(10);
                        }

                        foreach (FileInfo fileInPattern in new DirectoryInfo(parent).GetFiles(wildCard))
                        {
                            zip.AddItem(fileInPattern.FullName);
                        }
                    }
                    else
                    {
                        Console.WriteLine("Unabled to find file or folder: {0}", file);
                        Environment.Exit(10);
                    }
                }

                zip.Save(temporaryFile);
            }

            return temporaryFile;
        }
开发者ID:bendalton,项目名称:EnterpriseTester-API-Examples,代码行数:53,代码来源:Program.cs

示例2: button3_Click

 private void button3_Click(object sender, RoutedEventArgs e)
 {
     Directory.SetCurrentDirectory("C:/tmp/soundpcker");
     using (ZipFile zip = new ZipFile())
     {
         // add this map file into the "images" directory in the zip archive
         zip.AddFile("pack.mcmeta");
         // add the report into a different directory in the archive
         zip.AddItem("assets");
         zip.AddFile("lcrm");
         zip.Save("CustomSoundInjector_ResourcePack.zip");
     }
         SaveFileDialog saveFileDialog = new SaveFileDialog();
     saveFileDialog.DefaultExt = ".zip";
     saveFileDialog.Filter = "Minecraft ResourcePack (with Bytecode)|*.zip";
     if (saveFileDialog.ShowDialog() == true)
     {
         exportpath = saveFileDialog.FileName;
     }
     else
     {
         MessageBox.Show("Operation Cancelled.", "Cancelled", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     string originExport = "C:/tmp/soundpcker/CustomSoundInjector_ResourcePack.zip";
     File.Copy(originExport, exportpath, true);
     MessageBox.Show("Saved.", "Saved", MessageBoxButton.OK, MessageBoxImage.Information);
 }
开发者ID:GabrielTK,项目名称:MinecraftSoundChanger,代码行数:27,代码来源:EditMusicDisk.xaml.cs

示例3: ZipAndDeleteDirectory

 public void ZipAndDeleteDirectory(string directory, string zipFile)
 {
     var zip = new ZipFile();
     zip.AddItem(directory);
     zip.Save(zipFile);
     Directory.Delete(directory, true);
 }
开发者ID:gipasoft,项目名称:Sfera,代码行数:7,代码来源:FileSystem.cs

示例4: Zip

        public static bool Zip(string filePath, string TargetDirectory)
        {
            if (!File.Exists(filePath))
                throw new ApplicationException("");
            //if (!Directory.Exists(TargetDirectory))
            //    throw new ApplicationException("");

            bool rv = false;
            try
            {
                using (ZipFile zip = new ZipFile())
                {
                    zip.Password = ZipPassword;
                    zip.Comment = "";
                    //zip.AddFile(filePath);
                    zip.AddItem(filePath,"");
                    zip.Save(TargetDirectory);
                }
            }
            catch (Exception)
            {
                rv = false;
            }

            return rv;
        }
开发者ID:njmube,项目名称:FileProcessor,代码行数:26,代码来源:ZipHelper.cs

示例5: FileForm_Load

        private void FileForm_Load(object sender, EventArgs e)
        {
            this.Icon = Resources.icon;

            if (Clipboard.ContainsFileDropList())
            {

                var fileDropList = Clipboard.GetFileDropList();
                String now = DateTime.Now.ToString("yyyyMMdd_HHmmss");

                if (fileDropList.Count == 1)
                {
                    var path = fileDropList[0];
                    FileAttributes attr = File.GetAttributes(path);

                    if ((attr & FileAttributes.Directory) != FileAttributes.Directory)
                    {
                        var filename = Path.GetFileNameWithoutExtension(path) + "-" + now + Path.GetExtension(path);
                        File.Copy(path, Properties.Settings.Default.savefolder + @"\" + filename);
                        String url = Properties.Settings.Default.urlprefix + filename + Properties.Settings.Default.urlsuffix;

                        richTextBox1.Text += "Added file to Dropbox:\n" + filename;
                        Clipboard.SetDataObject(url, true);

                        return;
                    }
                }

                //Multiple files/directory, zip it
                using (ZipFile zip = new ZipFile())
                {
                    var files = new List<string>();

                    richTextBox1.Text += "Zipped and added multiple files to Dropbox:\n";
                    foreach (var file in fileDropList)
                    {
                        files.Add(file);
                        richTextBox1.Text += file + "\n";
                    }

                    var commonDir = FindCommonDirectoryPath.FindCommonPath("/", files);

                    foreach (var file in files)
                    {
                        zip.AddItem(file, commonDir);
                    }

                    var filename = now + ".zip";
                    zip.Save(Properties.Settings.Default.savefolder + @"\" + filename);
                    String url = Properties.Settings.Default.urlprefix + filename + Properties.Settings.Default.urlsuffix;

                    Clipboard.SetDataObject(url, true);
                    return;
                }

            }
        }
开发者ID:codebros,项目名称:ToDropbox,代码行数:57,代码来源:FileForm.cs

示例6: Download_MyDebtonator

        public ActionResult Download_MyDebtonator()
        {
            Response.Clear();

            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "filename=MyDebtonator.zip");

            using (ZipFile zip = new ZipFile())
            {
                var filePath = Server.MapPath("~/Content/downloads/my_debtonator/MydebtonatorInstaller.msi");
                zip.AddItem(filePath, "MyDebtonator");

                filePath = Server.MapPath("~/Content/downloads/my_debtonator/MydebtonatorInstaller.exe");
                zip.AddItem(filePath, "MyDebtonator");

                zip.Save(Response.OutputStream);
                Response.BufferOutput = false;
            }

            return View("Downloads");
        }
开发者ID:Joseph-Anthony-King,项目名称:Joseph-Anthony-King.com,代码行数:21,代码来源:HomeController.cs

示例7: BackUpFile

 /// <summary>
 /// 备份文件
 /// </summary>
 /// <param name="dirs"></param>
 /// <param name="path"></param>
 static void BackUpFile(string baseDir, string[] dirs, string path)
 {
     string fileName = string.Format(@"{0}\source.zip", path);
     List<string> list = new List<string>();
     //foreach (string dir in dirs)
     //{
     //    list.AddRange(GetFiles(dir));
     //}
     using (ZipFile zf = new ZipFile())
     {
         foreach (string dir in dirs)
         {
             zf.AddItem(baseDir + dir, dir);
         }
         zf.Save(fileName);
     }
 }
开发者ID:RainSong,项目名称:TOOLS,代码行数:22,代码来源:Program.cs

示例8: CreateZip_AddItem_WithDirectory

        public void CreateZip_AddItem_WithDirectory()
        {
            // select the name of the zip file
            string zipFileToCreate = "CreateZip_AddItem.zip";

            // create a bunch of files
            string subdir = "files";
            string[] filesToZip = TestUtilities.GenerateFilesFlat(subdir);

            // Create the zip archive
            using (ZipFile zip1 = new ZipFile())
            {
                //zip.StatusMessageTextWriter = System.Console.Out;
                for (int i = 0; i < filesToZip.Length; i++)
                    zip1.AddItem(filesToZip[i], "files");
                zip1.Save(zipFileToCreate);
            }

            // Verify the number of files in the zip
            Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate),
                                 filesToZip.Length);
        }
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:22,代码来源:BasicTests.cs

示例9: ZipFiles

        //public static bool ZipFiles(string outputFile, string password, List<string> inputFiles)
        public static bool ZipFiles(string outputFile, string password, string directoryToZip)
        {
            try
            {
                using (ZipFile zip = new ZipFile())
                {
                    if (!string.IsNullOrEmpty(password))
                    {
                        zip.Password = password.Replace(@"\", "").Trim();
                    }
                    //zip.AddFiles(inputFiles);

                    zip.AddItem(directoryToZip);
                    zip.Save(outputFile);
                }
            }
            catch (Exception ex)
            {
                string xxx = ex.ToString();
                return false;
            }
            return true;
        }
开发者ID:huyenvv,项目名称:bv74tw-tracnghiem,代码行数:24,代码来源:FileUtil.cs

示例10: VStudio_UnZip

        [Timeout(3 * 60 * 1000)]  // timeout in ms.
        public void VStudio_UnZip()
        {
            string zipFileToCreate = "VStudio_UnZip.zip";
            string shortDir = "files";
            string subdir = Path.Combine(TopLevelDir, shortDir);
            string extractDir = "extract";

            string[] filesToZip;
            Dictionary<string, byte[]> checksums;
            CreateFilesAndChecksums(subdir, out filesToZip, out checksums);

            // Create the zip archive
            //Directory.SetCurrentDirectory(TopLevelDir);
            using (ZipFile zip1 = new ZipFile())
            {
                for (int i = 0; i < filesToZip.Length; i++)
                    zip1.AddItem(filesToZip[i], shortDir);
                zip1.Save(zipFileToCreate);
            }

            // Verify the number of files in the zip
            Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length,
                                 "Incorrect number of entries in the zip file.");

            // unzip
            var decompressor = new Microsoft.VisualStudio.Zip.ZipFileDecompressor(zipFileToCreate, false, true, false);
            decompressor.UncompressToFolder(extractDir, false);

            // check the files in the extract dir
            VerifyChecksums(Path.Combine(extractDir, shortDir), filesToZip, checksums);

            // visual Studio's ZIP library doesn't bother with times...
            //VerifyNtfsTimes(Path.Combine(extractDir, "files"), filesToZip);
        }
开发者ID:jkingben,项目名称:DotNetZip.Semverd,代码行数:35,代码来源:Compatibility.cs

示例11: ShellApplication_Unzip_SFX

        public void ShellApplication_Unzip_SFX()
        {
            // get a set of files to zip up
            string subdir = Path.Combine(TopLevelDir, "files");
            string[] filesToZip;
            Dictionary<string, byte[]> checksums;
            CreateFilesAndChecksums(subdir, out filesToZip, out checksums);

            var script = GetScript("VbsUnzip-ShellApp.vbs");

            int i=0;
            foreach (var compLevel in compLevels)
            {
                // create and fill the directories
                string zipFileToCreate = Path.Combine(TopLevelDir, String.Format("ShellApp_Unzip_SFX.{0}.exe", i));
                string extractDir = Path.Combine(TopLevelDir, String.Format("extract.{0}",i));

                // Create the zip archive
                using (ZipFile zip1 = new ZipFile())
                {
                    zip1.CompressionLevel = (Ionic.Zlib.CompressionLevel) compLevel;
                    //zip.StatusMessageTextWriter = System.Console.Out;
                    for (int j = 0; j < filesToZip.Length; j++)
                        zip1.AddItem(filesToZip[j], "files");
                    zip1.SaveSelfExtractor(zipFileToCreate, SelfExtractorFlavor.ConsoleApplication);
                }

                // Verify the number of files in the zip
                Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate), filesToZip.Length,
                                     "Incorrect number of entries in the zip file.");

                // run the unzip script
                this.Exec(cscriptExe,
                          String.Format("\"{0}\" {1} {2}", script, zipFileToCreate, extractDir));

                // check the files in the extract dir
                VerifyChecksums(Path.Combine(extractDir, "files"), filesToZip, checksums);

                // verify the file times
                VerifyTimesDos(Path.Combine(extractDir, "files"), filesToZip);
                i++;
            }
        }
开发者ID:jkingben,项目名称:DotNetZip.Semverd,代码行数:43,代码来源:Compatibility.cs

示例12: CreateZip_AddFile_AddItem

        public void CreateZip_AddFile_AddItem()
        {
            string zipFileToCreate = "CreateZip_AddFile_AddItem.zip";
            string subdir = "files";
            string[] filesToZip = TestUtilities.GenerateFilesFlat(subdir);

            // use the parameterized ctor
            using (ZipFile zip1 = new ZipFile())
            {
                for (int i = 0; i < filesToZip.Length; i++)
                {
                    if (_rnd.Next(2) == 0)
                        zip1.AddFile(filesToZip[i], "files");
                    else
                        zip1.AddItem(filesToZip[i], "files");
                }
                zip1.Save(zipFileToCreate);
            }

            // Verify the number of files in the zip
            Assert.AreEqual<int>(TestUtilities.CountEntries(zipFileToCreate),
                                 filesToZip.Length);
        }
开发者ID:mattleibow,项目名称:Zip.Portable,代码行数:23,代码来源:BasicTests.cs

示例13: Download_SGVHS_VCDB

        public ActionResult Download_SGVHS_VCDB()
        {
            Response.Clear();

            Response.ContentType = "application/zip";
            Response.AddHeader("Content-Disposition", "filename=SGVHS-VCDB.zip");

            using (var zip = new ZipFile())
            {
                var filePath = Server.MapPath("~/Content/downloads/SGVHS_VCDB/SGVHS_VCDB_APP.zip");
                zip.AddItem(filePath, "SGVHS-VCDB");

                filePath = Server.MapPath("~/Content/downloads/SGVHS_VCDB/SGVHS_VCDB_Database.zip");
                zip.AddItem(filePath, "SGVHS-VCDB");

                zip.Save(Response.OutputStream);
                Response.BufferOutput = false;
            }

            return View("Downloads");
        }
开发者ID:Joseph-Anthony-King,项目名称:Joseph-Anthony-King.com,代码行数:21,代码来源:HomeController.cs

示例14: worker_DoWork

        private void worker_DoWork(object sender, DoWorkEventArgs e)
        {
            // create new zip file
            using (ZipFile zip = new ZipFile())
            {

                // trim each csv file
                foreach (ThirdCouncelorMLSFilesMLSFile csvFile in this.thirdCouncelorXml.CSVFiles)
                {
                    string newFilename = this.currentDirectory + "\\" + csvFile.Name;
                    string origFilename = newFilename + ".orig";
                    File.Move(newFilename, origFilename);

                    using (StreamReader origFile = new StreamReader(origFilename))
                    {
                        using (StreamWriter newFile = new StreamWriter(newFilename))
                        {
                            CSVTrimmer csvTrimmer = new CSVTrimmer(csvFile);
                            csvTrimmer.ExtractData(origFile, newFile);
                        }
                    }
                    // add new to zip file
                    zip.AddItem(newFilename, "");
                }
                zip.Save(this.currentDirectory + "\\" + "EQZipFile.zip");
            }

            Thread.Sleep(1000);

            // delete csv files
            StringBuilder sb = new StringBuilder();
            foreach (ThirdCouncelorMLSFilesMLSFile csvFile in this.thirdCouncelorXml.CSVFiles)
            {
                sb.Remove(0, sb.Length);
                sb.Append(this.currentDirectory);
                sb.Append("\\");
                sb.Append(csvFile.Name);
                File.Delete(sb.ToString());
                sb.Append(".orig");
                File.Delete(sb.ToString());
            }
        }
开发者ID:apippin,项目名称:tc,代码行数:42,代码来源:Window1.xaml.cs

示例15: test

 protected void test()
 {
     /* ��C:\TMP\TMP2\01.jpg �ļ�ѹ���� test01.zip �ļ��е� TMP\TMP2\01.jpg
      * 2:   * �� D:\02.jpg�ļ�ѹ���� test01.zip �ļ��е� 02.jpg
      * 3:   * �� C:\TMP\03.jpg�ļ�ѹ���� test01.zip �ļ��е� TMP\03.jpg
      * 4:   */
     using (ZipFile zip = new ZipFile(@"C:\test01.zip"))
     {
         zip.AddFile(@"C:\TMP\TMP2\01.jpg");
         zip.AddFile(@"D:\02.jpg");
         zip.AddFile(@"C:\TMP\03.jpg");
         zip.Save();
     }
     // �� TMP2 Ŀ¼ѹ���� test02.zip �ļ��е� TMP\TMP2 Ŀ¼
     using (ZipFile zip = new ZipFile(@"C:\test02.zip"))
     {
         zip.AddDirectory(@"C:\TMP\TMP2");
         zip.Save();
     }
     /* �� TMP2 Ŀ¼ѹ���� test03.zip �ļ��е� TTT Ŀ¼   21:
      * * �� C:\TMP\03.jpg�ļ�ѹ���� test03.zip �ļ��е� TTT\03.jpg   22:   */
     using (ZipFile zip = new ZipFile(@"C:\test03.zip"))
     {
         zip.AddFile(@"C:\TMP\03.jpg", "TTT");
         zip.AddItem(@"C:\TMP\TMP2", "TTT");
         zip.Save();
     }
     // �� C:\test03.zip �ļ���ѹ���� C:\
     using (ZipFile zip = new ZipFile(@"C:\test03.zip"))
     {
         zip.ExtractAll(@"C:\");
     }
 }
开发者ID:kingofhawks,项目名称:kcsj,代码行数:33,代码来源:RG_FuJian_List.aspx.cs


注:本文中的Ionic.Zip.ZipFile.AddItem方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。