Show / Hide Table of Contents

Delegate WriteDelegate

Delegate in which the application writes the ZipEntry content for the named entry.

Namespace: OfficeOpenXml.Packaging.Ionic.Zip
Assembly: EPPlus.dll
Syntax
public delegate void WriteDelegate(string entryName, Stream stream);
Parameters
Type Name Description
System.String entryName

The name of the entry that must be written.

System.IO.Stream stream

The stream to which the entry data should be written.

Remarks

When you add an entry and specify a WriteDelegate, via OfficeOpenXml.Packaging.Ionic.Zip.ZipFile.AddEntry(System.String,OfficeOpenXml.Packaging.Ionic.Zip.WriteDelegate), the application code provides the logic that writes the entry data directly into the zip file.

Examples

This example shows how to define a WriteDelegate that obtains a DataSet, and then writes the XML for the DataSet into the zip archive. There's no need to save the XML to a disk file first.

private void WriteEntry (String filename, Stream output)
{
    DataSet ds1 = ObtainDataSet();
    ds1.WriteXml(output);
}

private void Run()
{
    using (var zip = new ZipFile())
    {
        zip.AddEntry(zipEntryName, WriteEntry);
        zip.Save(zipFileName);
    }
}
Private Sub WriteEntry (ByVal filename As String, ByVal output As Stream)
    DataSet ds1 = ObtainDataSet()
    ds1.WriteXml(stream)
End Sub

Public Sub Run()
    Using zip = New ZipFile
        zip.AddEntry(zipEntryName, New WriteDelegate(AddressOf WriteEntry))
        zip.Save(zipFileName)
    End Using
End Sub

See Also

OfficeOpenXml.Packaging.Ionic.Zip.ZipFile.AddEntry(System.String,OfficeOpenXml.Packaging.Ionic.Zip.WriteDelegate)
In This Article
Back to top Generated by DocFX