PutNextEntry Method (entryName)

DotNetZip

Ionic Zip Library v1.9.1.6 PutNextEntry Method (entryName)
ReferenceIonic.ZipZipOutputStreamPutNextEntry(String)
Specify the name of the next entry that will be written to the zip file.
Declaration Syntax
C# Visual Basic Visual C++
public ZipEntry PutNextEntry(
	string entryName
)
Public Function PutNextEntry ( _
	entryName As String _
) As ZipEntry
public:
ZipEntry^ PutNextEntry(
	String^ entryName
)
Parameters
entryName (String)
The name of the entry to be added, including any path to be used within the zip file.
Return Value
The ZipEntry created.
Remarks

Call this method just before calling Write(array<Byte>[]()[][], Int32, Int32), to specify the name of the entry that the next set of bytes written to the ZipOutputStream belongs to. All subsequent calls to Write, until the next call to PutNextEntry, will be inserted into the named entry in the zip file.

If the entryName used in PutNextEntry() ends in a slash, then the entry added is marked as a directory. Because directory entries do not contain data, a call to Write(), before an intervening additional call to PutNextEntry(), will throw an exception.

If you don't call Write() between two calls to PutNextEntry(), the first entry is inserted into the zip file as a file of zero size. This may be what you want.

Because PutNextEntry() closes out the prior entry, if any, this method may throw if there is a problem with the prior entry.

This method returns the ZipEntry. You can modify public properties on the ZipEntry, such as Encryption, Password, and so on, until the first call to ZipOutputStream.Write(), or until the next call to PutNextEntry(). If you modify the ZipEntryafter having called Write(), you may get a runtime exception, or you may silently get an invalid zip archive.

Examples
This example shows how to create a zip file, using the ZipOutputStream class.
CopyC#
private void Zipup()
{
    using (FileStream fs raw = File.Open(_outputFileName, FileMode.Create, FileAccess.ReadWrite ))
    {
        using (var output= new ZipOutputStream(fs))
        {
            output.Password = "VerySecret!";
            output.Encryption = EncryptionAlgorithm.WinZipAes256;
            output.PutNextEntry("entry1.txt");
            byte[] buffer= System.Text.Encoding.ASCII.GetBytes("This is the content for entry #1.");
            output.Write(buffer,0,buffer.Length);
            output.PutNextEntry("entry2.txt");  // this will be zero length
            output.PutNextEntry("entry3.txt");
            buffer= System.Text.Encoding.ASCII.GetBytes("This is the content for entry #3.");
            output.Write(buffer,0,buffer.Length);
        }
    }
}

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