C# ZipArchiveEntry LastWriteTime
Description
ZipArchiveEntry LastWriteTime
Gets or sets the last
time the entry in the zip archive was changed.
Syntax
ZipArchiveEntry.LastWriteTime
has the following syntax.
public DateTimeOffset LastWriteTime { get; set; }
Example
The following example shows how to open an entry in a zip archive, modify it, and set the LastWriteTime property to the current time.
using System;/*from w ww . j ava2 s.c o m*/
using System.IO;
using System.IO.Compression;
class Program
{
static void Main(string[] args)
{
string zipPath = @"c:\example\result.zip";
using (ZipArchive archive = ZipFile.Open(zipPath, ZipArchiveMode.Update))
{
ZipArchiveEntry entry = archive.GetEntry("ExistingFile.txt");
using (StreamWriter writer = new StreamWriter(entry.Open()))
{
writer.BaseStream.Seek(0, SeekOrigin.End);
writer.WriteLine("append line to file");
}
entry.LastWriteTime = DateTimeOffset.UtcNow.LocalDateTime;
}
}
}