本文整理汇总了C#中ZipFile.RemoveEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.RemoveEntry方法的具体用法?C# ZipFile.RemoveEntry怎么用?C# ZipFile.RemoveEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipFile
的用法示例。
在下文中一共展示了ZipFile.RemoveEntry方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MainSuccessScenario
public void MainSuccessScenario()
{
var content1 = "content1 " + Guid.NewGuid();
var content2 = "content2 " + Guid.NewGuid();
using (var write = new ZipFile())
{
write.AddFileFromString("file1.txt", "", content1);
write.AddFileFromString("file2.txt", @"Dir1\Dir2\", content2);
write.AddDirectoryByName("Dir2/Dir3");
write.Save("testarc.zip");
write.Dispose();
}
using(var read = new ZipFile("testarc.zip"))
{
Assert.AreEqual(1, read.Entries.Where(e => e.IsDirectory).Count());
Assert.AreEqual(2, read.Entries.Where(e => !e.IsDirectory).Count());
var ms1 = new MemoryStream();
var ms2 = new MemoryStream();
read.Extract(@"file1.txt", ms1);
read.Extract(@"Dir1\Dir2\file2.txt", ms2);
ms1.Seek(0, SeekOrigin.Begin);
ms2.Seek(0, SeekOrigin.Begin);
read.Dispose();
Assert.AreEqual(content1, new StreamReader(ms1).ReadToEnd());
Assert.AreEqual(content2, new StreamReader(ms2).ReadToEnd());
}
using (var write2 = new ZipFile("testarc.zip"))
{
write2.RemoveEntry(@"file1.txt");
write2.Save();
write2.Dispose();
}
using (var read2 = new ZipFile("testarc.zip"))
{
Assert.AreEqual(1, read2.Entries.Where(e => !e.IsDirectory).Count());
Assert.AreEqual(1, read2.Entries.Where(e => e.IsDirectory).Count());
}
}