本文整理汇总了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);
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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();
}
}
示例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"));
}
示例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;
}
示例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);
}
}
示例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");
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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 )
{
}
}
示例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();
}
}