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


C# ZipFile.AddDirectory方法代码示例

本文整理汇总了C#中Ionic.Zip.ZipFile.AddDirectory方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.AddDirectory方法的具体用法?C# ZipFile.AddDirectory怎么用?C# ZipFile.AddDirectory使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Ionic.Zip.ZipFile的用法示例。


在下文中一共展示了ZipFile.AddDirectory方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Compress

 /// <summary>
 /// 压缩ZIP文件
 /// </summary>
 /// <param name="fileList">待压缩的文件或目录集合</param>
 /// <param name="zipName">压缩后的文件名</param>
 /// <param name="isDirStruct">是否按目录结构压缩</param>
 public static bool Compress(List<string> fileList, string zipName, bool isDirStruct)
 {
     try
     {
         using (var zip = new ZipFile(Encoding.Default))
         {
             foreach (string path in fileList)
             {
                 string fileName = Path.GetFileName(path);
                 if (Directory.Exists(path))
                 {
                     //按目录结构压缩
                     if (isDirStruct)
                     {
                         zip.AddDirectory(path, fileName);
                     }
                     else//目录下文件压缩到根目录
                     {
                         zip.AddDirectory(path);
                     }
                 }
                 if (File.Exists(path))
                 {
                     zip.AddFile(path);
                 }
             }
             zip.Save(zipName);
             return true;
         }
     }
     catch (Exception)
     {
         return false;
     }
 }
开发者ID:kevins1022,项目名称:Altman,代码行数:41,代码来源:ZipUtil.cs

示例2: AddFolderToZip

        private static void AddFolderToZip(ZipFile zipFile, string packageRootFolder, string addFolder)
        {
            string sourceFolder = Path.Combine(packageRootFolder, addFolder);

            if (Directory.Exists(sourceFolder))
                zipFile.AddDirectory(sourceFolder, addFolder);
        }
开发者ID:koav,项目名称:Rhetos,代码行数:7,代码来源:PackageCompiler.cs

示例3: Create

        public byte[] Create(string templateZipFileName, string projectName)
        {
            var temporaryZipFilePath = CreateTemporaryZippedTemplate(templateZipFileName);
            var temporaryRenamingFolder = Path.Combine(_downloadFolder, Path.GetFileNameWithoutExtension(temporaryZipFilePath));

            using (var zipFile = ZipFile.Read(temporaryZipFilePath))
            {
                zipFile.ExtractAll(temporaryRenamingFolder);
            }

            File.Delete(temporaryZipFilePath);

            var renamer = new SolutionRenamer(temporaryRenamingFolder, templateZipFileName, projectName);
            renamer.Rename();

            using (var zipFile = new ZipFile())
            {
                zipFile.AddDirectory(Path.Combine(temporaryRenamingFolder, projectName));
                zipFile.Save(Path.Combine(_downloadFolder, Path.GetFileNameWithoutExtension(temporaryZipFilePath) + ".zip"));
            }

            Directory.Delete(temporaryRenamingFolder, true);

            var bytes = File.ReadAllBytes(temporaryZipFilePath);

            File.Delete(temporaryZipFilePath);

            return bytes;
        }
开发者ID:andyshao,项目名称:aspnetboilerplate-website,代码行数:29,代码来源:ProjectCreator.cs

示例4: Run

        public void Run(string containerName)
        {
            if (!this.folderConnection.IsValid())
            {
                throw new DirectoryNotFoundException(string.Format("Unable to access {0}", this.folderConnection.Path));
            }

            List<string> containers = this.cloudConnection.GetContainers();

            if (containers.IsNullOrEmpty() || !containers.Contains(containerName))
            {
                throw new IndexOutOfRangeException(string.Format("Could not find Container: {0}", containerName));
            }

            using (var stream = new MemoryStream())
            {
                using (var zipFile = new ZipFile())
                {
                    zipFile.AddDirectory(this.folderConnection.Path);
                    zipFile.Save(stream);

                    stream.Seek(0, SeekOrigin.Begin);
                    this.cloudConnection.PutStorageItem(containerName, stream, this.folderConnection.ZipName);
                }
            }
        }
开发者ID:redbadger,项目名称:CloudFolderBackup,代码行数:26,代码来源:Uploader.cs

示例5: Main

            static void Main(string[] args) {
               
               string ZipFilePath = Path.Combine("", "TestArchive.zip");
               if (File.Exists(ZipFilePath)) File.Delete(ZipFilePath);
                var zip = new ZipFile(ZipFilePath);
                zip.AddDirectory("LocalVFS", "LocalVFS/");
                zip.Save();
                zip.Dispose();
                //
                ZipFileSystemConfiguration zc = ZipFileSystemConfiguration.CreateDefaultConfig(ZipFilePath,"_tmp_");
                ZipFileProvider lp = new ZipFileProvider(zc);
                bool exfd = lp.ExistFolder("LocalVFS/", true);
                if (exfd) {
                    lp.DeleteFolder("LocalVFS/");
                }
                byte[] dataTest = Encoding.UTF8.GetBytes("this is a test context!!!");
                File.WriteAllBytes("test.cs", dataTest);
                lp.CreateFolder("LocalVFS/");
                string filepath = lp.CreateFilePath("LocalVFS/", "test.txt");

                //lp.MoveFile("test.cs", filepath);
                byte[] dataTest2 = Encoding.UTF8.GetBytes("this is a test write data!!!");
                using (MemoryStream ms = new MemoryStream(dataTest2)) {
                    lp.WriteFile("LocalVFS/test.txt", ms, true, dataTest2.Length, ContentUtil.UnknownContentType);
                }
                //lp.DeleteFile("LocalVFS/test.txt");
                lp.CopyFolder("LocalVFS/", "localvfs_test/");
                lp.Dispose();
                int jj = 0;
            }
开发者ID:RainsSoft,项目名称:UJad-AI-VFS,代码行数:30,代码来源:_Test_ZipVFS_.cs

示例6: SaveButton_Click

		private void SaveButton_Click(object sender, EventArgs e)
		{
			SaveFileDialog Dialog = new SaveFileDialog();
			Dialog.Filter = "Zip Files (*.zip)|*.zip|AllFiles (*.*)|*.*";
			Dialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
			Dialog.FileName = Path.Combine(Dialog.InitialDirectory, "UGS-Diagnostics.zip");
			if(Dialog.ShowDialog() == DialogResult.OK)
			{
				string DiagnosticsFileName = Path.Combine(DataFolder, "Diagnostics.txt");
				try
				{
					File.WriteAllLines(DiagnosticsFileName, DiagnosticsTextBox.Lines);
				}
				catch(Exception Ex)
				{
					MessageBox.Show(String.Format("Couldn't write to '{0}'\n\n{1}", DiagnosticsFileName, Ex.ToString()));
					return;
				}

				string ZipFileName = Dialog.FileName;
				try
				{
					ZipFile Zip = new ZipFile();
					Zip.AddDirectory(DataFolder);
					Zip.Save(ZipFileName);
				}
				catch(Exception Ex)
				{
					MessageBox.Show(String.Format("Couldn't save '{0}'\n\n{1}", ZipFileName, Ex.ToString()));
					return;
				}
			}
		}
开发者ID:zhaoyizheng0930,项目名称:UnrealEngine,代码行数:33,代码来源:DiagnosticsWindow.cs

示例7: Archive

        public void Archive(string rootPath, string archiveFilename, CancellationToken cancellationToken, SimpleProgressCallback progressCallback = null)
        {
            using (ZipFile file = new ZipFile(archiveFilename))
            {
                // add all the files from the report to the zip file
                file.AddDirectory(rootPath);

                // subscribe for the archiving progress event
                file.SaveProgress += (sender, args) =>
                                         {
                                             // check if the cancellation was requested
                                             if (cancellationToken.IsCancellationRequested)
                                             {
                                                 args.Cancel = true;
                                                 return;
                                             }

                                             if (args.EntriesTotal == 0)
                                             {
                                                 // avoid division by zero
                                                 return;
                                             }

                                             progressCallback.TryInvoke((args.EntriesSaved + (args.TotalBytesToTransfer > 0 ? 1.0 * args.BytesTransferred / args.TotalBytesToTransfer : 0.0)) / args.EntriesTotal);
                                         };

                // safe file to disk
                file.Save();

                cancellationToken.ThrowIfCancellationRequested();
            }

            // report operation finished
            progressCallback.TryInvoke(1.0);
        }
开发者ID:korj,项目名称:Shtirlitz,代码行数:35,代码来源:DotNetZipArchiver.cs

示例8: CreateSelfExtractingZip

        /// <summary>
        /// Create a self-extracting ZIP using the DoNetZip library
        /// </summary>
        public static void CreateSelfExtractingZip(string outputFile, string tempFilePath, string productVersion, string productDescription, string installPath, string postExtractCommand)
        {
            if (!String.IsNullOrEmpty(outputFile))
            {
                using (var zip = new ZipFile())
                {
                    zip.AddDirectory(tempFilePath);

                    var options = new SelfExtractorSaveOptions
                    {
                        ProductName = productDescription,
                        ProductVersion = productVersion,
                        FileVersion = new System.Version(productVersion),
                        Description = productDescription,
                        Copyright = "Copyright © Influence Health 2015",
                        DefaultExtractDirectory = installPath,
                        Flavor = SelfExtractorFlavor.WinFormsApplication,
                        Quiet = false,
                        RemoveUnpackedFilesAfterExecute = false,
                        IconFile = Environment.CurrentDirectory + @"\Installer.ico",
                        ExtractExistingFile = ExtractExistingFileAction.OverwriteSilently,
                        PostExtractCommandLine = postExtractCommand
                    };
                    zip.SaveSelfExtractor(outputFile, options);
                }
            }
        }
开发者ID:rickeygalloway,项目名称:Test,代码行数:30,代码来源:PackageManagerBase.cs

示例9: BuildPackage

 public static void BuildPackage(IEnumerable<string> includes, string outputFileName)
 {
     File.Delete(outputFileName);
     using (var zipFile = new ZipFile(outputFileName))
     {
         foreach (var include in includes)
         {
             if (include.Length < 3)
             {
                 throw new PackManException("Include option must have following format: f|d|p:<value>.");
             }
             char type = char.ToLower(include[0]);
             string value = include.Substring(2);
             switch (type)
             {
                 case 'f':
                     zipFile.AddFile(value);
                     break;
                 case 'd':
                     zipFile.AddDirectory(value);
                     break;
                 case 'p':
                     zipFile.AddSelectedFiles(value,true);
                     break;
             }
         }
         zipFile.Save();
     }
 }
开发者ID:SzymonPobiega,项目名称:PackMan,代码行数:29,代码来源:PackageBuilder.cs

示例10: GetDiagnostics

        public HttpResponseMessage GetDiagnostics()
        {
            lock (_lockObj)
            {
                var response = new HttpResponseMessage();
                using (var zip = new ZipFile())
                {
                    foreach (var path in _paths)
                    {
                        if (Directory.Exists(path))
                        {
                            zip.AddDirectory(path, Path.GetFileName(path));
                        }
                    }

                    var ms = new MemoryStream();
                    zip.Save(ms);
                    response.Content = ms.AsContent();
                }
                response.Content.Headers.ContentType = new MediaTypeHeaderValue("application/zip");
                response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
                response.Content.Headers.ContentDisposition.FileName = String.Format("dump-{0:MM-dd-H:mm:ss}.zip", DateTime.UtcNow);
                return response;
            }
        }
开发者ID:loudej,项目名称:kudu,代码行数:25,代码来源:DiagnosticsService.cs

示例11: DoCopy

        public static void DoCopy()
        {
            using (var stream = new StreamReader(@"C:\CopyItems.xml"))
            {
                var deserializer = new XmlSerializer(typeof(List<CopyItem>));

                var items = (List<CopyItem>)deserializer.Deserialize(stream);
                log.Info($"Zdeserializowano elementy: liczba {items.Count}");

                foreach (var item in items)
                {
                    string date = DateTime.Now.ToShortDateString();

                    string mainDirPath = Path.Combine(item.Target, item.Name, date);
                    if (!Directory.Exists(mainDirPath))
                    {
                        Directory.CreateDirectory(mainDirPath);
                    }

                    using (ZipFile zip = new ZipFile())
                    {
                        zip.AddDirectory(item.Source);
                        
                        string path = Path.Combine(mainDirPath, Path.GetFileName(item.Source) + ".zip");

                        zip.Save(path);
                    }
                }
            }
        }
开发者ID:wlodarzmar,项目名称:AutoCopy,代码行数:30,代码来源:AutoCopier.cs

示例12: FolderToZip

 public void FolderToZip(string sourceDir, string path)
 {
     using (var surveyBackup = new ZipFile()) {
         surveyBackup.AddDirectory(sourceDir);
         surveyBackup.Save(path);
     }
 }
开发者ID:wurdum,项目名称:deployer,代码行数:7,代码来源:PackageManager.cs

示例13: GetPages

        public FileResult GetPages()
        {
            if (Request.Url != null)
            {
                var zip = new ZipFile();
                zip.AddDirectoryByName("Content");
                zip.AddDirectory(Server.MapPath("~/Content/"), "Content");
                var paths = DtoHelper.GetPaths();
                foreach (var path in paths)
                {
                    var url = Url.Action(path.Action, path.Controller, null, Request.Url.Scheme);
                    if (url != null)
                    {
                        var request = WebRequest.Create(string.Concat(url, Constants.Resources.DownloadParameter));
                        request.Credentials = CredentialCache.DefaultCredentials;
                        var response = (HttpWebResponse)request.GetResponse();
                        var dataStream = response.GetResponseStream();
                        {
                            if (dataStream != null)
                            {
                                zip.AddEntry(path.FileName, dataStream);
                            }
                        }
                    }
                }
                var stream = new MemoryStream();
                zip.Save(stream);
                stream.Position = 0;
                return new FileStreamResult(stream, "application/zip") { FileDownloadName = Constants.Resources.DownloadName };

            }
            return null;
        }
开发者ID:kreviuz,项目名称:Cms-Bsuir,代码行数:33,代码来源:DownLoadController.cs

示例14: DoubleZipFileContent

        public static void DoubleZipFileContent(string folderSource, string fileDest, string password)
        {
            using (var zip = new ZipFile())
            {
                zip.AlternateEncoding = Encoding.UTF8;
                zip.AlternateEncodingUsage = ZipOption.Always;

                zip.Password = password;
                zip.Encryption = EncryptionAlgorithm.WinZipAes128;
                zip.AddDirectory(folderSource);
                zip.Save(Path.Combine(folderSource, "content.zip"));
            }

            using (var doubleZip = new ZipFile())
            {
                doubleZip.AlternateEncoding = Encoding.UTF8;
                doubleZip.AlternateEncodingUsage = ZipOption.Always;

                doubleZip.Password = password;
                doubleZip.Encryption = EncryptionAlgorithm.WinZipAes128;
                doubleZip.AddFile(Path.Combine(folderSource, "content.zip"), "");
                doubleZip.Save(fileDest);
            }

            if (File.Exists(Path.Combine(folderSource, "content.zip")))
                File.Delete(Path.Combine(folderSource, "content.zip"));
        }
开发者ID:yetanothervan,项目名称:conspector,代码行数:27,代码来源:ZipHelper.cs

示例15: CreateSolution

        public string CreateSolution(IBuildBootstrappedSolutions bootstrapper, SolutionConfiguration configuration)
        {
            configuration.InCodeSubscriptions = true;
            foreach (var endpointConfiguration in configuration.EndpointConfigurations)
            {
                endpointConfiguration.InCodeSubscriptions = configuration.InCodeSubscriptions;
            }

            var solutionData = bootstrapper.BootstrapSolution(configuration);

            var solutionDirectory = SavePath + Guid.NewGuid();

            var solutionFile = SaveSolution(solutionDirectory, solutionData);

            InstallNuGetPackages(solutionDirectory, solutionData, solutionFile, NuGetExe);

            //AddReferencesToNugetPackages(solutionDirectory);

            var zipFilePath = solutionFile.Replace(".sln", ".zip");

            using (var zip = new ZipFile())
            {
                zip.AddDirectory(solutionDirectory, "Solution");
                zip.Save(zipFilePath);
            }

            return zipFilePath;
        }
开发者ID:ParticularLabs,项目名称:NServiceBus.Launchpad,代码行数:28,代码来源:SolutionSaver.cs


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