---
Product: Aspose.Email
Platform: net
Page Type: reference
Canonical URL: https://reference.aspose.org/email/net/cfb-writer
---

# CfbWriter

## Overview

`CfbWriter` serializes a `CfbDocument` into a valid Compound File Binary file. Call `ToBytes` to obtain the serialized content as a byte array, or `WriteFile` to write directly to disk. The internal `Serialize` method builds the FAT, DIFAT, mini-FAT, and directory sectors according to the MS-CFB specification. Constructors are used internally by the writer to represent entry records and sector chains.

## Constructors

| Signature | Description |
|-----------|-------------|
| `Serializer(document: CfbDocument)` | Creates a new `CfbWriter` with the specified parameters. |
| `EntryRecord(streamId: uint, name: string, objectType: DirectoryObjectType, clsid: byte[], stateBits: uint, creationTime: ulong, modifiedTime: ulong)` | Creates a new `CfbWriter` with the specified parameters. |
| `Chain(payload: byte[])` | Creates a new `CfbWriter` with the specified parameters. |

## Methods

| Signature | Description |
|-----------|-------------|
| `ToBytes(document: CfbDocument)` | Serializes `document` to a CFB-compliant byte array. |
| `WriteFile(document: CfbDocument, path: string)` | Serializes `document` and writes it to the file at `path`. |
| `Serialize()` | Performs the internal CFB layout: allocates FAT sectors, builds directory entries, and returns the complete binary. |

## Properties

| Name | Type | Access | Description |
|------|------|--------|-------------|
| `StreamId` | `uint` | Read | Zero-based directory index assigned to this entry record. |
| `Name` | `string` | Read | UTF-16LE entry name as it will appear in the CFB directory. |
| `ObjectType` | `DirectoryObjectType` | Read | The `DirectoryObjectType` value encoded in this entry's object-type byte. |
| `Clsid` | `byte[]` | Read | 16-byte CLSID written to this entry's CLSID field. |
| `StateBits` | `uint` | Read | Application-defined state bits written to this entry. |
| `CreationTime` | `ulong` | Read | Creation timestamp (FILETIME) written to this entry. |
| `ModifiedTime` | `ulong` | Read | Modification timestamp (FILETIME) written to this entry. |
| `StreamData` | `byte[]` | Read | Payload bytes for stream-type entries (empty for storage-type entries). |
| `Children` | `List<EntryRecord>` | Read | Ordered list of child `EntryRecord` entries for storage-type nodes. |
| `ColorFlag` | `DirectoryColorFlag` | Read | Red-black tree color written to this entry's directory record. |
| `LeftSiblingId` | `uint` | Read | Stream ID of the left sibling in the red-black tree. |
| `RightSiblingId` | `uint` | Read | Stream ID of the right sibling in the red-black tree. |
| `ChildId` | `uint` | Read | Stream ID of the first child entry (for storage-type nodes). |
| `StartingSectorLocation` | `uint` | Read | First FAT sector index for this stream's data. |
| `StreamSize` | `ulong` | Read | Size in bytes of the stream's data payload. |
| `IsRoot` | `bool` | Read | True if this entry is the root storage entry (stream ID 0). |
| `IsStorage` | `bool` | Read | True if this entry is a storage container. |
| `IsStream` | `bool` | Read | True if this entry is a data stream. |
| `Payload` | `byte[]` | Read | The complete serialized bytes of this entry (used internally by the chain builder). |
| `Sectors` | `List<uint>` | Read | Ordered list of FAT sector indices allocated to this entry's data. |
| `FirstSector` | `uint` | Read | Index of the first FAT sector allocated to this entry's data. |

## See Also
- [Aspose.Email for .NET — Enterprise API Reference](https://reference.aspose.com/email/net/)