UpdateFile Method (fileName)

DotNetZip

Ionic Zip Library v1.9.1.6 UpdateFile Method (fileName)
ReferenceIonic.ZipZipFileUpdateFile(String)
Adds or Updates a File in a Zip file archive.
Declaration Syntax
C# Visual Basic Visual C++
public ZipEntry UpdateFile(
	string fileName
)
Public Function UpdateFile ( _
	fileName As String _
) As ZipEntry
public:
ZipEntry^ UpdateFile(
	String^ fileName
)
Parameters
fileName (String)
The name of the file to add or update. It should refer to a file in the filesystem. The name of the file may be a relative path or a fully-qualified path.
Return Value
The ZipEntry corresponding to the File that was added or updated.
Remarks

This method adds a file to a zip archive, or, if the file already exists in the zip archive, this method Updates the content of that given filename in the zip archive. The UpdateFile method might more accurately be called "AddOrUpdateFile".

Upon success, there is no way for the application to learn whether the file was added versus updated.

For ZipFile properties including Encryption, Password, SetCompression, ProvisionalAlternateEncoding, ExtractExistingFile, ZipErrorAction, and CompressionLevel, their respective values at the time of this call will be applied to the ZipEntry added.

Examples
This example shows how to Update an existing entry in a zipfile. The first call to UpdateFile adds the file to the newly-created zip archive. The second call to UpdateFile updates the content for that file in the zip archive.
CopyC#
using (ZipFile zip1 = new ZipFile())
{
  // UpdateFile might more accurately be called "AddOrUpdateFile"
  zip1.UpdateFile("MyDocuments\\Readme.txt");
  zip1.UpdateFile("CustomerList.csv");
  zip1.Comment = "This zip archive has been created.";
  zip1.Save("Content.zip");
}

using (ZipFile zip2 = ZipFile.Read("Content.zip"))
{
  zip2.UpdateFile("Updates\\Readme.txt");
  zip2.Comment = "This zip archive has been updated: The Readme.txt file has been changed.";
  zip2.Save();
}
CopyVB.NET
Using zip1 As New ZipFile
    ' UpdateFile might more accurately be called "AddOrUpdateFile"
    zip1.UpdateFile("MyDocuments\Readme.txt")
    zip1.UpdateFile("CustomerList.csv")
    zip1.Comment = "This zip archive has been created."
    zip1.Save("Content.zip")
End Using

Using zip2 As ZipFile = ZipFile.Read("Content.zip")
    zip2.UpdateFile("Updates\Readme.txt")
    zip2.Comment = "This zip archive has been updated: The Readme.txt file has been changed."
    zip2.Save
End Using

Assembly: Ionic.Zip (Module: Ionic.Zip) Version: 1.9.1.8 (1.9.1.8)