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


C# ZipArchive.CreateEntryFromFolder方法代码示例

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


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

示例1: CanAddEmptyFolder

        public void CanAddEmptyFolder()
        {
            string tempDir = GetTempDir();
            string newZipPath = Path.Combine(tempDir, "test.zip");

            string newDirName = "wat";
            string newDirPath = Path.Combine(tempDir, newDirName);
            Directory.CreateDirectory(newDirPath);

            using (var stream = new FileStream(newZipPath, FileMode.Create))
                using (var zip = new ZipArchive(stream, ZipArchiveMode.Create))
                    zip.CreateEntryFromFolder(newDirPath, newDirName);

            using (var stream = new FileStream(newZipPath, FileMode.Open))
                using (var zip = new ZipArchive(stream, ZipArchiveMode.Read))
                    Assert.NotNull(zip.GetEntry(newDirName + "/"));
        }
开发者ID:rzhw,项目名称:MoreZipFileExtensions,代码行数:17,代码来源:CreateEntryFromFolderTests.cs

示例2: CanAddFoldersWithFilesAndFolders

        public void CanAddFoldersWithFilesAndFolders()
        {
            string tempDir = GetTempDir();
            string newZipPath = Path.Combine(tempDir, "test.zip");

            string newDirName = "wat";
            string newDirPath = Path.Combine(tempDir, newDirName);
            Directory.CreateDirectory(newDirPath);
            string newDirName2 = "watwat";
            string newDir2Name = "gonna pop some tags";
            string newDir2Path = Path.Combine(tempDir, newDir2Name);
            Directory.CreateDirectory(newDir2Path);

            string newDirNewFile1Name = "test1.txt";
            string newDirNewFile1Path = Path.Combine(newDirPath, newDirNewFile1Name);
            File.WriteAllText(newDirNewFile1Path, "i have no idea what i'm doing");

            string newDirNewFile2Name = "test2.txt";
            string newDirNewFile2Path = Path.Combine(newDirPath, newDirNewFile2Name);
            File.WriteAllText(newDirNewFile2Path, "pls halp");

            string newDirNewDir1Name = "test3";
            string newDirNewDir1Path = Path.Combine(newDirPath, newDirNewDir1Name);
            Directory.CreateDirectory(newDirNewDir1Path);

            string newDirNewDir2Name = "test4";
            string newDirNewDir2Path = Path.Combine(newDirPath, newDirNewDir2Name);
            Directory.CreateDirectory(newDirNewDir2Path);

            string newDirNewDir2NewFile1Name = "test5.txt";
            string newDirNewDir2NewFile1Path = Path.Combine(newDirNewDir2Path, newDirNewDir2NewFile1Name);
            File.WriteAllText(newDirNewDir2NewFile1Path, "i crie evertim");

            string newFileName = "testRoot.txt";
            string newFilePath = Path.Combine(tempDir, newFileName);
            File.WriteAllText(newFilePath, "only got twenty dollars in my pocket");

            using (var stream = new FileStream(newZipPath, FileMode.Create))
            using (var zip = new ZipArchive(stream, ZipArchiveMode.Create))
            {
                zip.CreateEntryFromFolder(newDirPath, newDirName);
                zip.CreateEntryFromFolder(newDirPath, newDirName2);
                zip.CreateEntryFromFolder(newDirPath, newDir2Name);
                zip.CreateEntryFromFile(newFilePath, newFileName);
            }

            using (var stream = new FileStream(newZipPath, FileMode.Open))
            using (var zip = new ZipArchive(stream, ZipArchiveMode.Read))
            {
                Assert.NotNull(zip.GetEntry(newDirName + "/"));
                Assert.NotNull(zip.GetEntry(newDirName + "/" + newDirNewFile1Name));
                Assert.NotNull(zip.GetEntry(newDirName + "/" + newDirNewFile2Name));
                Assert.NotNull(zip.GetEntry(newDirName + "/" + newDirNewDir1Name + "/"));
                Assert.NotNull(zip.GetEntry(newDirName + "/" + newDirNewDir2Name + "/"));
                Assert.NotNull(zip.GetEntry(newDirName + "/" + newDirNewDir2Name + "/" + newDirNewDir2NewFile1Name));
                Assert.NotNull(zip.GetEntry(newDirName2 + "/"));
                Assert.NotNull(zip.GetEntry(newDirName2 + "/" + newDirNewFile1Name));
                Assert.NotNull(zip.GetEntry(newDirName2 + "/" + newDirNewFile2Name));
                Assert.NotNull(zip.GetEntry(newDirName2 + "/" + newDirNewDir1Name + "/"));
                Assert.NotNull(zip.GetEntry(newDirName2 + "/" + newDirNewDir2Name + "/"));
                Assert.NotNull(zip.GetEntry(newDirName2 + "/" + newDirNewDir2Name + "/" + newDirNewDir2NewFile1Name));
                Assert.NotNull(zip.GetEntry(newDir2Name + "/"));
                Assert.NotNull(zip.GetEntry(newFileName));
            }
        }
开发者ID:rzhw,项目名称:MoreZipFileExtensions,代码行数:65,代码来源:CreateEntryFromFolderTests.cs

示例3: CanAddFolderWithFiles

        public void CanAddFolderWithFiles()
        {
            string tempDir = GetTempDir();
            string newZipPath = Path.Combine(tempDir, "test.zip");

            string newDirName = "wat";
            string newDirPath = Path.Combine(tempDir, newDirName);
            Directory.CreateDirectory(newDirPath);

            string newDirNewFile1Name = "test1.txt";
            string newDirNewFile1Path = Path.Combine(newDirPath, newDirNewFile1Name);
            File.WriteAllText(newDirNewFile1Path, "i have no idea what i'm doing");

            string newDirNewFile2Name = "test2.txt";
            string newDirNewFile2Path = Path.Combine(newDirPath, newDirNewFile2Name);
            File.WriteAllText(newDirNewFile2Path, "pls halp");

            using (var stream = new FileStream(newZipPath, FileMode.Create))
            using (var zip = new ZipArchive(stream, ZipArchiveMode.Create))
                zip.CreateEntryFromFolder(newDirPath, newDirName);

            using (var stream = new FileStream(newZipPath, FileMode.Open))
            using (var zip = new ZipArchive(stream, ZipArchiveMode.Read))
            {
                Assert.NotNull(zip.GetEntry(newDirName + "/"));
                Assert.NotNull(zip.GetEntry(newDirName + "/" + newDirNewFile1Name));
                Assert.NotNull(zip.GetEntry(newDirName + "/" + newDirNewFile2Name));
            }
        }
开发者ID:rzhw,项目名称:MoreZipFileExtensions,代码行数:29,代码来源:CreateEntryFromFolderTests.cs


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