本文整理汇总了C#中Ionic.Zip.ZipFile.AddEntry方法的典型用法代码示例。如果您正苦于以下问题:C# ZipFile.AddEntry方法的具体用法?C# ZipFile.AddEntry怎么用?C# ZipFile.AddEntry使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Ionic.Zip.ZipFile
的用法示例。
在下文中一共展示了ZipFile.AddEntry方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
using (ZipFile zip = new ZipFile())
{
Stationery s = new Stationery();
StampStationery ss = new StampStationery();
byte[] stationery = s.CreateStationary();
byte[] sStationery = ss.ManipulatePdf(
ss.CreatePdf(), stationery
);
byte[] insertPages = ManipulatePdf(sStationery, stationery);
zip.AddEntry(RESULT1, insertPages);
// reorder the pages in the PDF
PdfReader reader = new PdfReader(insertPages);
reader.SelectPages("3-41,1-2");
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
}
zip.AddEntry(RESULT2, ms.ToArray());
}
zip.AddEntry(Utility.ResultFileName(s.ToString() + ".pdf"), stationery);
zip.AddEntry(Utility.ResultFileName(ss.ToString() + ".pdf"), sStationery);
zip.Save(stream);
}
}
示例2: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
using (ZipFile zip = new ZipFile())
{
HelloWorld h = new HelloWorld();
byte[] pdf = Utility.PdfBytes(h);
// Create a reader
PdfReader reader = new PdfReader(pdf);
string js = File.ReadAllText(
Path.Combine(Utility.ResourceJavaScript, RESOURCE)
);
using (MemoryStream ms = new MemoryStream())
{
using (PdfStamper stamper = new PdfStamper(reader, ms))
{
// Add some javascript
stamper.JavaScript = js;
}
zip.AddEntry(RESULT, ms.ToArray());
}
zip.AddEntry(RESOURCE, js);
zip.AddEntry(Utility.ResultFileName(h.ToString() + ".pdf"), pdf);
zip.Save(stream);
}
}
示例3: OutputZip
public void OutputZip(HttpResponseBase response,
FileHandle dataFile,
IEnumerable<FileHandle> photoFiles,
IEnumerable<StreamHandle> docmentStreams,
string downloadTokenValue,
string zipFilename)
{
using (var zip = new ZipFile())
{
zip.UseZip64WhenSaving = Zip64Option.AsNecessary;
var pdfList = new List<FileHandle>();
if (dataFile != null) pdfList.Add(dataFile);
pdfList.AddRange(photoFiles);
PrepareResponse(response, downloadTokenValue, zipFilename);
foreach (var pdfHolder in pdfList)
{
zip.AddEntry(pdfHolder.FileName, pdfHolder.Content);
}
foreach (var document in docmentStreams)
{
if (document.ContentStream != null)
{
zip.AddEntry(document.FileName, document.ContentStream);
}
}
zip.Save(response.OutputStream);
}
}
示例4: Save
/// <summary>
/// Create a TOC from the chapters and create the file
/// </summary>
/// <param name="filename"></param>
public void Save(string filename)
{
using (ZipFile zippedBook = new ZipFile())
{
zippedBook.ForceNoCompression = true;
ZipEntry mimetype = zippedBook.AddEntry("mimetype", "", "application/epub+zip");
zippedBook.ForceNoCompression = false;
zippedBook.AddEntry("container.xml", "META-INF", GetResource("EPubLib.Files.META_INF.container.xml"));
zippedBook.AddEntry("content.opf", "OEBPS", GetContentOpf(), Encoding.UTF8);
zippedBook.AddEntry("toc.ncx", "OEBPS", GetToc(), Encoding.UTF8);
foreach (Chapter chapter in GetChapters())
{
zippedBook.AddEntry("chapter" + chapter.Number.ToString("000") + ".xhtml", "OEBPS", chapter.Content, Encoding.UTF8);
}
foreach (FileItem image in GetImages())
{
zippedBook.AddEntry(image.Name, "OEBPS/images", image.Data);
}
zippedBook.Save(filename);
}
}
示例5: ImportActionShouldAddTestsToProblemIfZipFileIsCorrect
public void ImportActionShouldAddTestsToProblemIfZipFileIsCorrect()
{
var zipFile = new ZipFile();
var inputTest = "input";
var outputTest = "output";
zipFile.AddEntry("test.001.in.txt", inputTest);
zipFile.AddEntry("test.001.out.txt", outputTest);
var zipStream = new MemoryStream();
zipFile.Save(zipStream);
zipStream = new MemoryStream(zipStream.ToArray());
this.File.Setup(x => x.ContentLength).Returns(1);
this.File.Setup(x => x.FileName).Returns("file.zip");
this.File.Setup(x => x.InputStream).Returns(zipStream);
var redirectResult = this.TestsController.Import("1", this.File.Object, false, false) as RedirectToRouteResult;
Assert.IsNotNull(redirectResult);
Assert.AreEqual("Problem", redirectResult.RouteValues["action"]);
Assert.AreEqual(1, redirectResult.RouteValues["id"]);
var tests = this.Data.Problems.All().First(pr => pr.Id == 1).Tests.Count;
Assert.AreEqual(14, tests);
var tempDataHasKey = this.TestsController.TempData.ContainsKey(GlobalConstants.InfoMessage);
Assert.IsTrue(tempDataHasKey);
var tempDataMessage = this.TestsController.TempData[GlobalConstants.InfoMessage];
Assert.AreEqual("Тестовете са добавени към задачата", tempDataMessage);
}
示例6: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream)
{
// Use old example to create PDF
MovieTemplates mt = new MovieTemplates();
byte[] pdf = Utility.PdfBytes(mt);
using (ZipFile zip = new ZipFile())
{
using (MemoryStream ms = new MemoryStream())
{
// step 1
using (Document document = new Document())
{
// step 2
PdfWriter writer = PdfWriter.GetInstance(document, ms);
// step 3
document.Open();
// step 4
PdfPTable table = new PdfPTable(2);
PdfReader reader = new PdfReader(pdf);
int n = reader.NumberOfPages;
PdfImportedPage page;
for (int i = 1; i <= n; i++)
{
page = writer.GetImportedPage(reader, i);
table.AddCell(Image.GetInstance(page));
}
document.Add(table);
}
zip.AddEntry(RESULT, ms.ToArray());
}
zip.AddEntry(Utility.ResultFileName(mt.ToString() + ".pdf"), pdf);
zip.Save(stream);
}
}
示例7: ExportImpl
public override void ExportImpl(System.Windows.Window parentWindow, Data.DataMatrix matrix, string datasetName, object options)
{
var opts = options as DarwinCoreExporterOptions;
var columnNames = new List<String>();
matrix.Columns.ForEach(col => {
if (!col.IsHidden) {
columnNames.Add(col.Name);
}
});
datasetName = SystemUtils.StripIllegalFilenameChars(datasetName);
using (ZipFile archive = new ZipFile(opts.Filename)) {
archive.AddEntry(String.Format("{0}\\occurrence.txt", datasetName), (String name, Stream stream) => {
ExportToCSV(matrix, stream, opts, true);
});
archive.AddEntry(String.Format("{0}\\meta.xml", datasetName), (String name, Stream stream) => {
WriteMetaXml(stream, opts, columnNames);
});
archive.Save();
}
}
示例8: Strip
public byte[] Strip(ZipFile zip, Dictionary<string, Tuple<Cipher, byte[]>> sessionKeys)
{
IEnumerable<ZipEntry> entriesToDecrypt = zip.Entries.Where(e => !META_NAMES.Contains(e.FileName));
using (var output = new ZipFile(Encoding.UTF8))
{
output.UseZip64WhenSaving = Zip64Option.Never;
output.CompressionLevel = CompressionLevel.None;
using (var s = new MemoryStream())
{
zip["mimetype"].Extract(s);
output.AddEntry("mimetype", s.ToArray());
}
foreach (var file in entriesToDecrypt)
{
byte[] data;
using (var s = new MemoryStream())
{
file.Extract(s);
data = s.ToArray();
}
if (sessionKeys.ContainsKey(file.FileName))
data = Decryptor.Decrypt(data, sessionKeys[file.FileName].Item1, sessionKeys[file.FileName].Item2);
var ext = Path.GetExtension(file.FileName);
output.CompressionLevel = UncompressibleExts.Contains(ext) ? CompressionLevel.None : CompressionLevel.BestCompression;
output.AddEntry(file.FileName, data);
}
using (var result = new MemoryStream())
{
output.Save(result);
return result.ToArray();
}
}
}
示例9: CompileNewXAP
public static string CompileNewXAP(HashSet<string> fullsetOfDlls, string shared)
{
var tempPath = Path.Combine(shared, Guid.NewGuid() + ".xap");
using (
var stream = Assembly.GetExecutingAssembly()
.GetManifestResourceStream("sl_runner.xap.sl-50-xap.xap"))
using (var baseZip = ZipFile.Read(stream))
{
var set = new HashSet<string>();
var item = baseZip["AppManifest.xaml"];
var xml = XDocument.Parse(new StreamReader(item.OpenReader()).ReadToEnd());
using (
var zip = new ZipFile()
{
CompressionLevel = CompressionLevel.Default,
CompressionMethod = CompressionMethod.Deflate
})
{
zip.AddEntry("AppManifest.xaml", new byte[] { });
foreach (var entry in baseZip.Entries)
{
if (entry.FileName.Contains(".dll"))
{
using (var memstream = new MemoryStream())
{
entry.OpenReader().CopyTo(memstream);
memstream.Seek(0, SeekOrigin.Begin);
zip.AddEntry(entry.FileName, memstream.ToArray());
set.Add(Path.GetFileName(entry.FileName));
}
}
}
var desc = xml.DescendantNodes().OfType<XElement>();
var parts = desc.Single(it => it.Name.LocalName.Contains("Deployment.Parts"));
foreach (var dll in fullsetOfDlls)
{
if (set.Contains(Path.GetFileName(dll)))
continue;
set.Add(Path.GetFileName(dll));
zip.AddFile(dll, "");
parts.Add(new XElement(XName.Get("AssemblyPart", "http://schemas.microsoft.com/client/2007/deployment"),
new XAttribute(
XName.Get("Name", "http://schemas.microsoft.com/winfx/2006/xaml"),
Path.GetFileNameWithoutExtension(dll)),
new XAttribute("Source", Path.GetFileName(dll))));
}
using (var memstream = new MemoryStream())
{
xml.Save(memstream, SaveOptions.OmitDuplicateNamespaces);
zip.UpdateEntry("AppManifest.xaml", memstream.ToArray());
}
zip.Save(tempPath);
}
}
return tempPath;
}
示例10: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream) {
using (ZipFile zip = new ZipFile()) {
CompressImage c = new CompressImage();
zip.AddEntry(RESULT1, c.CreatePdf(false));
zip.AddEntry(RESULT2, c.CreatePdf(true));
zip.AddFile(Path.Combine(Utility.ResourceImage, RESOURCE), "");
zip.Save(stream);
}
}
示例11: Write
// ---------------------------------------------------------------------------
public void Write(Stream stream) {
using (ZipFile zip = new ZipFile()) {
MetadataPdf metadata = new MetadataPdf();
byte[] pdf = metadata.CreatePdf();
zip.AddEntry(RESULT1, pdf);
zip.AddEntry(RESULT2, metadata.ManipulatePdf(pdf));
zip.Save(stream);
}
}
示例12: Write
// ---------------------------------------------------------------------------
public override void Write(Stream stream) {
using (ZipFile zip = new ZipFile()) {
HtmlMovies2 movies = new HtmlMovies2();
// create a StyleSheet
StyleSheet styles = new StyleSheet();
styles.LoadTagStyle("ul", "indent", "10");
styles.LoadTagStyle("li", "leading", "14");
styles.LoadStyle("country", "i", "");
styles.LoadStyle("country", "color", "#008080");
styles.LoadStyle("director", "b", "");
styles.LoadStyle("director", "color", "midnightblue");
movies.SetStyles(styles);
// create extra properties
Dictionary<String,Object> map = new Dictionary<String, Object>();
map.Add(HTMLWorker.FONT_PROVIDER, new MyFontFactory());
map.Add(HTMLWorker.IMG_PROVIDER, new MyImageFactory());
movies.SetProviders(map);
// creates HTML and PDF (reusing a method from the super class)
byte[] pdf = movies.CreateHtmlAndPdf(stream);
zip.AddEntry(HTML, movies.Html.ToString());
zip.AddEntry(RESULT1, pdf);
zip.AddEntry(RESULT2, movies.CreatePdf());
// add the images so the static html file works
foreach (Movie movie in PojoFactory.GetMovies()) {
zip.AddFile(
Path.Combine(
Utility.ResourcePosters,
string.Format("{0}.jpg", movie.Imdb)
),
""
);
}
zip.Save(stream);
}
}