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


C# ZipArchive.AddFolder方法代码示例

本文整理汇总了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)
                {
                }
            }
        }
开发者ID:haunthy,项目名称:sensus,代码行数:101,代码来源:LocalDataStore.cs


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