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


C# ZipFile.UpdateFile方法代码示例

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


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

示例1: Error_Save_NonExistentFile

        public void Error_Save_NonExistentFile()
        {
            int j;
            string repeatedLine;
            string filename;
            string zipFileToCreate = Path.Combine(TopLevelDir, "Error_Save_NonExistentFile.zip");

            // create the subdirectory
            string Subdir = Path.Combine(TopLevelDir, "DirToZip");
            Directory.CreateDirectory(Subdir);

            int entriesAdded = 0;
            // create the files
            int numFilesToCreate = _rnd.Next(20) + 18;
            for (j = 0; j < numFilesToCreate; j++)
            {
                filename = Path.Combine(Subdir, String.Format("file{0:D3}.txt", j));
                repeatedLine = String.Format("This line is repeated over and over and over in file {0}",
                    Path.GetFileName(filename));
                TestUtilities.CreateAndFillFileText(filename, repeatedLine, _rnd.Next(1800) + 1500);
                entriesAdded++;
            }

            string tempFileFolder = Path.Combine(TopLevelDir, "Temp");
            Directory.CreateDirectory(tempFileFolder);
            TestContext.WriteLine("Using {0} as the temp file folder....", tempFileFolder);
            String[] tfiles = Directory.GetFiles(tempFileFolder);
            int nTemp = tfiles.Length;
            TestContext.WriteLine("There are {0} files in the temp file folder.", nTemp);
            String[] filenames = Directory.GetFiles(Subdir);

            var a1 = System.Reflection.Assembly.GetExecutingAssembly();
            String myName = a1.GetName().ToString();
            string toDay = System.DateTime.Now.ToString("yyyy-MMM-dd");

            try
            {
                using (ZipFile zip = new ZipFile(zipFileToCreate))
                {
                    zip.TempFileFolder = tempFileFolder;
                    zip.CompressionLevel = Ionic.Zlib.CompressionLevel.None;

                    TestContext.WriteLine("Zipping {0} files...", filenames.Length);

                    int count = 0;
                    foreach (string fn in filenames)
                    {
                        count++;
                        TestContext.WriteLine("  {0}", fn);

                        string file = fn;

                        if (count == filenames.Length - 2)
                        {
                            file += "xx";
                            TestContext.WriteLine("(Injecting a failure...)");
                        }

                        zip.UpdateFile(file, myName + '-' + toDay + "_done");
                    }
                    TestContext.WriteLine("\n");
                    zip.Save();
                    TestContext.WriteLine("Zip Completed '{0}'", zipFileToCreate);
                }
            }
            catch (Exception ex)
            {
                TestContext.WriteLine("Zip Failed (EXPECTED): {0}", ex.Message);
            }

            tfiles = Directory.GetFiles(tempFileFolder);

            Assert.AreEqual<int>(nTemp, tfiles.Length,
                    "There are unexpected files remaining in the TempFileFolder.");
        }
开发者ID:Belxjander,项目名称:Asuna,代码行数:75,代码来源:ErrorTests.cs


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