本文整理汇总了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 + "/"));
}
示例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));
}
}
示例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));
}
}