Class OleObjectCollection

OleObjectCollection class

Represents a collection containing the instances of the OleObject class.

public sealed class OleObjectCollection : IList<OleObject>

Methods

NameDescription
Clear()Clears the collection. In order to persist these changes project.Save should be called with new MPPSaveOptions { WriteViewData = true; }
GetEnumerator()Returns an enumerator for this collection.
ToList()Converts the instance of the OleObjectCollection class to a list containing the instances of the OleObject class.

Examples

Shows how to work with collection of OLE objects.

IDictionary<string, string> extensions = new Dictionary<string, string>
{
    { "RTF", "_rtfFile_out.rtf" },
    { "MSWordDoc", "_wordFile_out.docx" },
    { "ExcelML12", "_excelFile_out.xlsx" }
};

var project = new Project(DataDir + "Embedded.mpp");

// by using index access
// List<OleObject> list = project.OleObjects.ToList();
// for (var index = 0; index < list.Count; index++)
// {
// var oleObject = list[index];
// }

// or enumeration one can iterate over OLE objects
foreach (var oleObject in project.OleObjects)
{
    if (string.IsNullOrEmpty(oleObject.FileFormat) || !extensions.ContainsKey(oleObject.FileFormat))
    {
        continue;
    }

    var path = OutDir + "EmbeddedContent_" + extensions[oleObject.FileFormat];
    using (var stream = new FileStream(path, FileMode.Create))
    {
        stream.Write(oleObject.Content, 0, oleObject.Content.Length);
    }
}

See Also