Source Property (Attachment Object)

Source Property (Attachment Object)

The Source property returns or sets information specifying the location of the data for the attachment. Read/write.

Syntax

objAttachment.Source

Data Type

String or Object (Message)

Remarks

The Source property returns or sets the full path and file name of the file containing the data for CdoFileLink attachments. It returns or sets the OLE class name of the attachment for CdoOLE attachments. For CdoEmbeddedMessage attachments, the Source property is set with the ID property of the message to be embedded, but it returns the Message object itself. An embedded message is copied into the attachment at creation time.

Note that the Source property is a string except when it returns the source of an CdoEmbeddedMessage attachment.

CDO does not synchronize the Source property and the ReadFromFile method. For CdoFileData and CdoOLE attachments, when you change the Source property to indicate a different file, you must also explicitly call the ReadFromFile method to update the object data. Similarly, when you call ReadFromFile with data from a different file, you must change the Source property.

The return value or setting of the Source property depends on the value of the Type property, as described in the following table:

Type property

Source property

CdoFileData

Specifies a full path and file name that contains the data for the attachment, for example C:\DOCUMENT\BUDGET.XLS.

CdoFileLink

Specifies a full path and file name in a universal naming convention (UNC) format, such as \\SALES\INFO\PRODUCTS\NEWS.DOC.

CdoOLE

Specifies a full path and file name to a valid OLE docfile, for example C:\DOCUMENT\BUDGET2.XLS.

CdoEmbeddedMessage

Specifies the unique identifier of the message to be embedded; returns the embedded Message object.

The UNC format is suitable for sending attachments to recipients who have access to a common file server.

Note   You must set Type before you set Source. Failure to do this can result in a return of CdoE_NOT_FOUND from the ReadFromFile or WriteToFile method.

The Source property can also be set at the time of creation of the attachment by supplying the source parameter to the Add method of the Attachments collection. For attachments of type CdoFileData, the Add method is the only place the source file can be specified. However, you can change it later with the Attachment object's ReadFromFile method.

You should always set Source before displaying the attachment, because some calendaring clients, such as Microsoft® Outlook®, return an error message when you attempt to display an AppointmentItem, MeetingItem, or Message object with an empty attachment, that is, an attachment with no properties set.

The Source property corresponds to the MAPI property PR_ATTACH_PATHNAME. It can be rendered into HTML hypertext using the CDO Rendering ObjectRenderer object. To specify this, set the object renderer's DataSource property to this Attachment object and the property parameter of the RenderProperty method to CdoPR_ATTACH_PATHNAME.

Example

' from the function Attachments_Add()
    Set objAttach = objAttachColl.Add ' add an attachment
    With objAttach
        .Type = CdoFileLink
        .Position = 0 ' place at beginning of message
        .Source = "\\server\bitmaps\honey.bmp" ' UNC name
    End With
    ' must update the message to save the new info
    objOneMsg.Update ' update the message
    MsgBox "Added an attachment of type CdoFileLink"
 

See Also

Concepts

Attachment Object