本文整理汇总了C#中ZipArchive.AddFolder方法的典型用法代码示例。如果您正苦于以下问题:C# ZipArchive.AddFolder方法的具体用法?C# ZipArchive.AddFolder怎么用?C# ZipArchive.AddFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZipArchive
的用法示例。
在下文中一共展示了ZipArchive.AddFolder方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteDataToZipFile
//.........这里部分代码省略.........
// close all files
foreach (StreamWriter file in datumTypeFile.Values)
{
file.Write(Environment.NewLine + "]");
file.Close();
}
cancellationToken.ThrowIfCancellationRequested();
if (progressCallback != null)
progressCallback("Compressing data...", 0);
#if __ANDROID__
directoryName += '/';
zipFile = new ZipOutputStream(new FileStream(zipPath, FileMode.Create, FileAccess.Write));
zipFile.PutNextEntry(new ZipEntry(directoryName));
int dataWritten = 0;
foreach (string path in Directory.GetFiles(directory))
{
// start json file for data of current type
zipFile.PutNextEntry(new ZipEntry(directoryName + Path.GetFileName(path)));
using (StreamReader file = new StreamReader(path))
{
string line;
while ((line = file.ReadLine()) != null)
{
if (progressCallback != null && totalDataCount >= 10 && (dataWritten % (totalDataCount / 10)) == 0)
progressCallback(null, dataWritten / (double)totalDataCount);
cancellationToken.ThrowIfCancellationRequested();
zipFile.Write(file.CurrentEncoding.GetBytes(line + Environment.NewLine));
if (line != "[" && line != "]")
++dataWritten;
}
}
zipFile.CloseEntry();
System.IO.File.Delete(path);
}
// close entry for directory
zipFile.CloseEntry();
#elif __IOS__
zipFile = new ZipArchive();
zipFile.CreateZipFile(zipPath);
zipFile.AddFolder(directory, null);
#endif
if (progressCallback != null)
progressCallback(null, 1);
return totalDataCount;
}
finally
{
// ensure that zip file is closed.
try
{
if (zipFile != null)
{
#if __ANDROID__
zipFile.Close();
#elif __IOS__
zipFile.CloseZipFile();
#endif
}
}
catch (Exception)
{
}
// ensure that all temporary files are closed/deleted.
foreach (string datumType in datumTypeFile.Keys)
{
try
{
datumTypeFile[datumType].Close();
}
catch (Exception)
{
}
}
try
{
Directory.Delete(directory, true);
}
catch (Exception)
{
}
}
}