Add Method

Add Method

The Add method adds a new BodyPart object to the collection.

Syntax

Function Add([ByVal Index as Long = -1]) as IBodyPartHRESULT Add( long Index = -1, IBodyPart** pVal);

Parameters

  • Index
    The ordinal index within the collection at which the new object is added. The first element in the collection has an index value of 1, and the last element has an index value equal to Count. Setting the Index to 1 causes the new object to be inserted at the beginning of the collection. Setting the Indexto -1 causes the new object to be appended to the collection. Index settings of 0 or less than -1 are invalid.

Remarks

The Index parameter allows a BodyPart object to be inserted into a specific location in the collection.

If an object already exists in the collection with the index value that you specify, then that object and all following objects have their index value increased by one, and the object is then inserted. Using the Add method to insert and object does not replace the object at the index value you specify.

The content type for the newly added BodyPart object defaults to application/octet-stream.

The content disposition for the newly added BodyPart object defaults to attachment if the BodyParts collection contains attachments. (that is, if it was retrieved using an Attachments property on another object, such as the Message object.) The filename attribute parameter, however, is not set automatically.

Example

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Windows 2000 Library
Dim iMsg as New CDO.Message
Dim iBp as IBodyPart
Dim iBps as IBodyParts

Set iBps = iMsg.BodyPart.BodyParts
Set iBp = iBps.Add
...