System.IO.Compression.ZipArchive.CreateEntry C# (CSharp) Method

CreateEntry() public method

Creates an empty entry in the Zip archive with the specified entry name. There are no restrictions on the names of entries. The last write time of the entry is set to the current time. If an entry with the specified name already exists in the archive, a second entry will be created that has an identical name.
entryName is a zero-length string. entryName is null. The ZipArchive does not support writing. The ZipArchive has already been closed.
public CreateEntry ( string entryName, CompressionLevel compressionLevel ) : ZipArchiveEntry
entryName string A path relative to the root of the archive, indicating the name of the entry to be created.
compressionLevel CompressionLevel The level of the compression (speed/memory vs. compressed size trade-off).
return ZipArchiveEntry
        public ZipArchiveEntry CreateEntry(string entryName, CompressionLevel compressionLevel)
        {
            Contract.Ensures(Contract.Result<ZipArchiveEntry>() != null);
            Contract.EndContractBlock();

            return DoCreateEntry(entryName, compressionLevel);
        }

Same methods

ZipArchive::CreateEntry ( string entryName ) : System.IO.Compression.ZipArchiveEntry
ZipArchive::CreateEntry ( string entryName, System compressionLevel ) : System.IO.Compression.ZipArchiveEntry
ZipArchive::CreateEntry ( string entryName ) : ZipArchiveEntry

Usage Example

        public async Task <MemoryStream> GenerateZip(string report, string log)
        {
            using var ms      = new MemoryStream();
            using var archive =
                      new System.IO.Compression.ZipArchive(ms, ZipArchiveMode.Create, true);
            byte[] reportBytes = Encoding.ASCII.GetBytes(report);
            byte[] logBytes    = Encoding.ASCII.GetBytes(log);

            var zipEntry = archive.CreateEntry("Report.trx",
                                               CompressionLevel.Fastest);

            using (var zipStream = zipEntry.Open())
            {
                await zipStream.WriteAsync(reportBytes, 0, reportBytes.Length).ConfigureAwait(false);
            }

            var zipEntry2 = archive.CreateEntry("log.txt",
                                                CompressionLevel.Fastest);

            using (var zipStream = zipEntry2.Open())
            {
                await zipStream.WriteAsync(logBytes, 0, logBytes.Length).ConfigureAwait(false);
            }
            return(ms);
        }
All Usage Examples Of System.IO.Compression.ZipArchive::CreateEntry