Discuss this help topic in SecureBlackbox Forum

Read or write stream entry in compound storage

To read or write a stream entry in CFB storage you need to get TElCompoundFileVirtualStream object using TElCompoundFileStreamEntry.Stream property of the entry you want to read or write. Alternatively you can get the stream using TElCompoundFileStreamEntry.GetStream() method to get the child stream object by name.

Use the obtained Stream object to read and write the data. When finished, call Stream.Close() method to properly update the data in the storage.

C#:


byte[] Buf = new byte[1];
TElCompoundFileVirtualStream VS =
  Document.BinaryDocument.Storage.RootEntry.CreateStream("StreamName").Stream;
try
{
    VS.Write(Buf, 0, Buf.Length);
}
finally
{
    VS.Close();
}
Delphi:

var
  VS: TElCompoundFileVirtualStream;
  Buf: ByteArray;
begin
  SetLength(Buf, 1);
  VS :=
    Document.BinaryDocument.Storage.RootEntry.CreateStream('StreamName').Stream;
  try
    VS.Write(Buf[0], Length(Buf));
  finally
    VS.Close(); // !!! In Delphi TElCompoundFileVirtualStream also has Close() method
  end;
end;

How To articles about MS Office binary documents

Discuss this help topic in SecureBlackbox Forum