Guide to use CFBF.Net

An example on how to read a "subject" property from Microsoft Outlook Message (.msg) using CFBF Component

  1. Add a reference to CFBF.Net project / dll within your project
  2. Add these line in your code
    //create an instance of CompoundFileBinaryFileFormatReader
    using (var cfbf = new CompoundFileBinaryFileFormatReader("8.msg"))
    {
    //Parse the message
    cfbf.Parse();
    }
  3. After parsing you will get a List of DirectoryEntry in cfbf.DirectoryEntries
    (Each storage object or stream object within a compound file is represented by a single directory entry)
  4. Add the following lines to your code to get Stream of subject property
    using (var cfbf = new CompoundFileBinaryFileFormatReader("8.msg"))
    {
    cfbf.Parse();

    //Get Direcotory entry of the subject property
    DirectoryEntry dirEntry = cfbf.GetDirectoriesEntryByName("0037001F").FirstOrDefault();

     
    //Get the Stream for the subject property
    using (var  stream = cfbf.GetDirectoryEntryStream(dirEntry)) 
    {
    //Extrac the text from the stream
    stream.Position = 0;
    byte[] buff = new byte[stream.Length];
    stream.Read(buff, 0, (
    int)stream.Length - 1);

    //Convert byte array to string
    var subject = System.Text.ASCIIEncoding.Unicode.GetString(buff);

     }
    }

Last edited May 8, 2013 at 5:20 AM by ssaliba, version 4

Comments

No comments yet.