本文整理汇总了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.");
}