Back to Devexpress

ZipArchive.AddByteArray(String, Byte[]) Method

officefileapi-devexpress-dot-compression-dot-ziparchive-dot-addbytearray-x28-system-dot-string-system-dot-byte-x29.md

latest4.3 KB
Original Source

ZipArchive.AddByteArray(String, Byte[]) Method

Creates a zip item from a byte array and adds it to archive.

Namespace : DevExpress.Compression

Assembly : DevExpress.Docs.v25.2.dll

NuGet Package : DevExpress.Document.Processor

Declaration

csharp
public ZipByteArrayItem AddByteArray(
    string name,
    byte[] content
)
vb
Public Function AddByteArray(
    name As String,
    content As Byte()
) As ZipByteArrayItem

Parameters

NameTypeDescription
nameString

A string that is the name of the zip item.

| | content | Byte[] |

A Byte[] array to compress and store in a zip item.

|

Returns

TypeDescription
ZipByteArrayItem

A ZipByteArrayItem object that is the compressed array of bytes in an archive.

|

Remarks

This code snippet adds a byte array to an archive as an item with the name “myByteArray” and outputs zipped data to the stream.

View Example

csharp
using DevExpress.Compression;

public void ArchiveByteArray() {
    byte[] myByteArray = Enumerable.Repeat((byte)0x78, 10000).ToArray();
    using (Stream myZippedStream = new FileStream("ArchiveByteArray.zip", FileMode.Create)) {
        using (ZipArchive archive = new ZipArchive()) {
            archive.AddByteArray("myByteArray", myByteArray);
            archive.Save(myZippedStream);
        }
    }
}
vb
Imports DevExpress.Compression
        Public Sub ArchiveByteArray()
            Dim myByteArray() As Byte = Enumerable.Repeat(CByte(&H78), 10000).ToArray()
            Using myZippedStream As Stream = New FileStream("ArchiveByteArray.zip", FileMode.Create)
                Using archive As New ZipArchive()
                    archive.AddByteArray("myByteArray", myByteArray)
                    archive.Save(myZippedStream)
                End Using
            End Using
        End Sub

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the AddByteArray(String, Byte[]) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

zip-compression-and-archive-api-examples/CS/CompressionLibraryExamples/ZipExamples.cs#L172

csharp
using (ZipArchive archive = new ZipArchive()) {
    archive.AddByteArray("myByteArray", myByteArray);
    archive.Save(myZippedStream);

zip-compression-and-archive-api-examples/VB/CompressionLibraryExamples/ZipExamples.vb#L177

vb
Using archive As New ZipArchive()
    archive.AddByteArray("myByteArray", myByteArray)
    archive.Save(myZippedStream)

See Also

ZipArchive Class

ZipArchive Members

DevExpress.Compression Namespace