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


C# ZipFile.AddFile方法代码示例

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


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

示例1: button3_Click

 private void button3_Click(object sender, RoutedEventArgs e)
 {
     Directory.SetCurrentDirectory("C:/tmp/soundpcker");
     using (ZipFile zip = new ZipFile())
     {
         // add this map file into the "images" directory in the zip archive
         zip.AddFile("pack.mcmeta");
         // add the report into a different directory in the archive
         zip.AddItem("assets");
         zip.AddFile("lcrm");
         zip.Save("CustomSoundInjector_ResourcePack.zip");
     }
         SaveFileDialog saveFileDialog = new SaveFileDialog();
     saveFileDialog.DefaultExt = ".zip";
     saveFileDialog.Filter = "Minecraft ResourcePack (with Bytecode)|*.zip";
     if (saveFileDialog.ShowDialog() == true)
     {
         exportpath = saveFileDialog.FileName;
     }
     else
     {
         MessageBox.Show("Operation Cancelled.", "Cancelled", MessageBoxButton.OK, MessageBoxImage.Error);
     }
     string originExport = "C:/tmp/soundpcker/CustomSoundInjector_ResourcePack.zip";
     File.Copy(originExport, exportpath, true);
     MessageBox.Show("Saved.", "Saved", MessageBoxButton.OK, MessageBoxImage.Information);
 }
开发者ID:GabrielTK,项目名称:MinecraftSoundChanger,代码行数:27,代码来源:EditMusicDisk.xaml.cs

示例2: Main

        static void Main(string[] args)
        {
            const string releaseDir = @"";
            var assemblyPath = Path.Combine(Path.Combine(Environment.CurrentDirectory, releaseDir), "LINQPadLog4jDriver.dll");
            var assembly = Assembly.LoadFile(assemblyPath);
            var version = assembly.GetName().Version;

            using (var ms = new MemoryStream())
            using (var releaseZip = new ZipFile())
            using (var lpx45 = new ZipFile())
            {
                var releaseZipPath = Path.Combine(releaseDir, string.Format("Log4jLinqpadDriver {0}.zip", version));
                lpx45.AddFile(Path.Combine(Environment.CurrentDirectory, "LINQPadLog4jDriver.dll"), "");
                lpx45.AddFile(Path.Combine(Environment.CurrentDirectory, "header.xml"), "");
                lpx45.Save(ms);
                ms.Seek(0, SeekOrigin.Begin);
                releaseZip.AddEntry("Log4jLinqpadDriver.lpx", ms);

                releaseZip.Save(releaseZipPath);
                ms.SetLength(0);

                // readme
                releaseZip.AddFile(Path.Combine(releaseDir, "readme.txt"), "");
                releaseZip.Save(releaseZipPath);
            }

            // open
            Process.Start(Environment.CurrentDirectory);
        }
开发者ID:BerserkerDotNet,项目名称:LINQPadLog4jDriver,代码行数:29,代码来源:Program.cs

示例3: BackUp

        public bool BackUp(string tableName)
        {
            string pathTable = databasePath + '/' + tableName + ".dat";
            string pathHash = databasePath + '/' + tableName + "_hash.dat";
            string pathFreeSpace = databasePath + '/' + tableName + "_freespace.dat";
            string pathHeaders = databasePath + '/' + tableName + "_headers.dat";
            try
            {
                using (ZipFile zip = new ZipFile())
                {
                    zip.AddFile(pathTable);
                    zip.AddFile(pathHash);
                    zip.AddFile(pathFreeSpace);
                    zip.AddFile(pathHeaders);

                    zip.Save(tableName + ".zip");
                }
                return true;
            }
            catch (Exception ex)
            {
                Logger.Write(ex);
                return false;
            }
        }
开发者ID:Kozitsin,项目名称:DatabaseLab,代码行数:25,代码来源:Database.cs

示例4: SaveZipFile

        public static void SaveZipFile(this ISaveableContent saveable, string fileName)
        {
            // Make sure all files are relative
            List<string> allFiles = saveable.GetReferencedFiles(RelativeType.Absolute);

            string directory = FileManager.GetDirectory(fileName);

            foreach (string referencedFile in allFiles)
            {
                if (!FileManager.IsRelativeTo(referencedFile, directory))
                {
                    throw new InvalidOperationException("The file " +
                        referencedFile + " is not relative to the destination file " +
                        fileName + ".  All files must be relative to create a ZIP.");
                }
            }

            // First save the XML - we'll need this
            string xmlFileName = FileManager.RemoveExtension(fileName) + ".xmlInternal";
            FileManager.XmlSerialize(saveable, xmlFileName);

            using (ZipFile zip = new ZipFile())
            {
                // add this map file into the "images" directory in the zip archive
                zip.AddFile(xmlFileName);
                foreach (string referencedFile in allFiles)
                {
                    zip.AddFile(referencedFile);
                }
                zip.Save(fileName);
            }
        }
开发者ID:vchelaru,项目名称:FlatRedBall,代码行数:32,代码来源:SaveableContentExtensionMethods.cs

示例5: OnExecute

		/// <summary>
		/// Do the work.
		/// </summary>
		protected override void OnExecute(ServerCommandProcessor theProcessor)
		{
			using (ZipFile zip = new ZipFile(_zipFile))
			{
				zip.ForceNoCompression = !NasSettings.Default.CompressZipFiles;
				zip.TempFileFolder = _tempFolder;
				zip.Comment = String.Format("Archive for study {0}", _studyXml.StudyInstanceUid);
				zip.UseZip64WhenSaving = Zip64Option.AsNecessary;

				// Add the studyXml file
				zip.AddFile(Path.Combine(_studyFolder,String.Format("{0}.xml",_studyXml.StudyInstanceUid)), String.Empty);

				// Add the studyXml.gz file
				zip.AddFile(Path.Combine(_studyFolder, String.Format("{0}.xml.gz", _studyXml.StudyInstanceUid)), String.Empty);

			    string uidMapXmlPath = Path.Combine(_studyFolder, "UidMap.xml");
                if (File.Exists(uidMapXmlPath))
                    zip.AddFile(uidMapXmlPath, String.Empty);

				// Add each sop from the StudyXmlFile
				foreach (SeriesXml seriesXml in _studyXml)
					foreach (InstanceXml instanceXml in seriesXml)
					{
						string filename = Path.Combine(_studyFolder, seriesXml.SeriesInstanceUid);
						filename = Path.Combine(filename, String.Format("{0}.dcm", instanceXml.SopInstanceUid));

						zip.AddFile(filename, seriesXml.SeriesInstanceUid);
					}

				zip.Save();
			}
		}
开发者ID:fparisotto,项目名称:ClearCanvas-Contrib,代码行数:35,代码来源:CreateStudyZipCommand.cs

示例6: BatchDownload

        public ActionResult BatchDownload(string items)
        {
            var i = items.Split('_');
            var applications = db.Applications.Where(p => i.Contains(SqlFunctions.StringConvert((double)p.id).Trim()));

            var savePath = Server.MapPath("~/App_Data/");
            using (ZipFile zip = new ZipFile())
            {
                foreach (var application in applications)
                {
                    foreach (var attachment in application.ApplicationAttachments)
                    {
                        if (!String.IsNullOrEmpty(attachment.filename) && !String.IsNullOrEmpty(attachment.filepath))
                        {
                            var filename = attachment.filename;
                            var path = Server.MapPath("~/App_Data/" + attachment.filepath);
                            var filepath = Path.Combine(path, filename);
                            if (System.IO.File.Exists(filepath))
                            {
                                zip.AddFile(filepath, Path.Combine("ByApplication", application.StudentProfile.name + "[" + application.StudentProfile.academic_organization + "]" + "_" + application.StudentProfile.id + "_" + application.id));
                                //zip.AddFile(filepath, Path.Combine("ByAttachmentType", application.program_id.ToString() + "_" + HttpUtility.UrlEncode(application.Program.name), attachment.ProgramApplicationAttachment.name)).FileName = application.StudentProfile.name + "[" + application.StudentProfile.academic_organization + "]" + "_" + application.StudentProfile.id + "_" + application.id + "_" + filename;
                                zip.AddFile(filepath).FileName = Path.Combine("ByAttachmentType"
                                    , application.program_id.ToString() + "_" + HttpUtility.UrlEncode(application.Program.name)
                                    , attachment.ProgramApplicationAttachment.name
                                    , application.StudentProfile.name + "[" + application.StudentProfile.academic_organization + "]" + "_" + application.StudentProfile.id + "_" + application.id + "_" + filename);
                            }
                        }
                    }
                }
                zip.Save(savePath + "Archive.zip");
            }
            return File(savePath + "Archive.zip", "application/octet-stream", Path.GetFileName(savePath + "Archive.zip"));
        }
开发者ID:horizon1711,项目名称:SchoolOfScience,代码行数:33,代码来源:ApplicationController.cs

示例7: CreateArchiveFile

        private string CreateArchiveFile()
        {
            string filename = Path.Combine(_storagePath, DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".zip");
            using(ZipFile output = new ZipFile())
            {
                output.UseZip64WhenSaving = Ionic.Zip.Zip64Option.AsNecessary;
                output.CompressionLevel = Ionic.Zlib.CompressionLevel.BestSpeed;
                output.SortEntriesBeforeSaving = false;
                output.AddFile(Path.Combine(_storagePath, "content.index"), "");

                foreach (KeyValuePair<string, ContentRecord> rec in _content)
                {
                    string relpath = _content.GetContentFile(rec.Value);
                    if (relpath != null)
                    {
                        relpath = relpath.Substring(_storagePath.Length).TrimStart('\\', '/');
                        output.AddFile(Path.Combine(_storagePath, relpath), Path.GetDirectoryName(relpath));
                    }
                }

                string idxPath = Path.Combine(_storagePath, "index");
                if (Directory.Exists(idxPath))
                    foreach (string file in Directory.GetFiles(idxPath))
                        output.AddFile(file, "index");

                output.Save(filename);
            }
            return filename;
        }
开发者ID:modulexcite,项目名称:httpclone,代码行数:29,代码来源:SitePublisher.cs

示例8: Write

// --------------------------------------------------------------------------- 
    public void Write(Stream stream) {
      using (ZipFile zip = new ZipFile()) {
        PagedImages p = new PagedImages();
        zip.AddEntry(RESULT, p.CreatePdf());
        zip.AddFile(RESOURCE1, "");
        zip.AddFile(RESOURCE2, "");
        zip.AddFile(RESOURCE3, "");
        zip.Save(stream);
      }
    }    
开发者ID:kuujinbo,项目名称:iTextInAction2Ed,代码行数:11,代码来源:PagedImages.cs

示例9: btnZip_Click

 protected void btnZip_Click(object sender, EventArgs e)
 {
     using (ZipFile zip = new ZipFile())
     {
         // add this map file into the "images" directory in the zip archive
         zip.AddFile(@"E:\own\VS2012 Project\VipSoft\trunk\Demo\Web\ConfigHelper.cs","");
         // add the report into a different directory in the archive
         zip.AddFile(@"E:\own\VS2012 Project\VipSoft\trunk\Demo\Web\CriteriaTest.aspx", "");
         zip.Save(@"E:\own\VS2012 Project\VipSoft\trunk\Demo\Web\Jimmy.zip");
     }
 }
开发者ID:eicrosoft,项目名称:VipSoft,代码行数:11,代码来源:ZipArchive.aspx.cs

示例10: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        using (var zip = new ZipFile())
        {
            var imagePath = Server.MapPath("~/Images/Sam.jpg");
            zip.AddFile(imagePath, string.Empty);
            zip.AddFile(imagePath, "My Images");

            zip.AddEntry("ZIPInfo.txt", "This ZIP file was created on " + DateTime.Now);

            var saveToFilePath = Server.MapPath("~/PictureOfSam2.zip");
            zip.Save(saveToFilePath);
        }
    }
开发者ID:gnikwerdna,项目名称:zipfile-1,代码行数:14,代码来源:CodeListing2.aspx.cs

示例11: CreateBackupZip

        public virtual string CreateBackupZip()
        {
            var dbFile = _enviromentProvider.GetNzbDronoeDbFile();
            var configFile = _enviromentProvider.GetConfigPath();
            var zipFile = _enviromentProvider.GetConfigBackupFile();

            using (var zip = new ZipFile())
            {
                zip.AddFile(dbFile, String.Empty);
                zip.AddFile(configFile, String.Empty);
                zip.Save(zipFile);
            }

            return zipFile;
        }
开发者ID:ShironDrake,项目名称:NzbDrone,代码行数:15,代码来源:BackupProvider.cs

示例12: ZipFiles

        public static void ZipFiles(string zipFile, string rootPath, string[] files)
        {
			using (ZipFile zip = new ZipFile())
			{
				//use unicode if necessary
				zip.UseUnicodeAsNecessary = true;
				//skip locked files
				zip.ZipErrorAction = ZipErrorAction.Skip;
				foreach (string file in files)
				{
					string fullPath = Path.Combine(rootPath, file);
					if (Directory.Exists(fullPath))
					{
						//add directory with the same directory name
						zip.AddDirectory(fullPath, file);
					}
					else if (File.Exists(fullPath))
					{
						//add file to the root folder
						zip.AddFile(fullPath, "");
					}
				}
				zip.Save(zipFile);
			}
        }
开发者ID:jordan49,项目名称:websitepanel,代码行数:25,代码来源:FileUtils.cs

示例13: 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

示例14: SendCrashReport

        public static void SendCrashReport(string body, string type)
        {
            try
            {
                string destfile = Path.Combine(Path.GetTempPath(), "error_report.zip");
                if (File.Exists(destfile))
                    File.Delete(destfile);

                using (var zip = new ZipFile(destfile))
                {
                        zip.AddFile(ServiceProvider.LogFile, "");
                        zip.Save(destfile);
                }
                var client = new MailgunClient("digicamcontrol.mailgun.org", "key-6n75wci5cpuz74vsxfcwfkf-t8v74g82");
                var message = new MailMessage("[email protected]", "[email protected]")
                                  {
                                      Subject = (type ?? "Log file"),
                                      Body = "Client Id" + (ServiceProvider.Settings.ClientId ?? "") + "\n" + body,
                                  };
                message.Attachments.Add(new Attachment(destfile));

                client.SendMail(message);
                message.Dispose();
            }
            catch (Exception )
            {

            }
        }
开发者ID:brunoklein99,项目名称:nikon-camera-control,代码行数:29,代码来源:HelpProvider.cs

示例15: Serialize

        /// <summary>
        /// Serialize
        /// </summary>
        /// <param name="site">site</param>
        /// <param name="path">path</param>
        /// <returns></returns>
        public void Serialize(Site site, string path)
        {
            if (site == null)
            {
                throw new ArgumentException("site");
            }
            if (string.IsNullOrWhiteSpace(path))
            {
                throw new ArgumentException("stream");
            }

            var tempPath = Path.GetTempPath() + "site.xml";
            using (var stream = File.Create(tempPath))
            {
                var serializer = new XmlSerializer(typeof(Site));
                serializer.Serialize(stream, site);
            }

            var packagePath = path + Path.DirectorySeparatorChar + site.Name + ".wbp";
            if (File.Exists(packagePath))
            {
                File.Delete(packagePath);

            }
            using (ZipFile package = new ZipFile(packagePath, Console.Out))
            {
                package.AddFile(tempPath, string.Empty);
                package.AddFiles(site.Resources.Select(r => r.TextData).Where(File.Exists), "resources");
                package.Save();
            }
        }
开发者ID:WebCentrum,项目名称:WebPackUI,代码行数:37,代码来源:SiteSerializer.cs


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