다음을 통해 공유


Adding Attachments to Appointments and Meetings

Topic Last Modified: 2006-06-11

You can add attachments to appointments and meetings. For example, you could attach an image of a map to a meeting to show where the meeting is located.

Attachments are added by using the Attachments collection of the Appointment object. Attachments are saved with the Appointment object in the Exchange store.

To add an attachment to an appointment or a meeting

  1. Create the Appointment object and set its properties.
  2. Create the attachment body part by calling the Add method on the attachments collection.
  3. Set the content type and content transfer encoding fields of the body part.
  4. Get the default stream from the attachment body part.
  5. Load the file being attached into the default stream, and save it back to the attachment body part.
  6. For meetings, create a calendar message, add attendees, and send the meeting request.
  7. Save the appointment or meeting to the organizer's calendar folder (optional).

The following example shows how to add the attachment d:\maps\directions_e2k7.gif to a meeting.

Example

Visual Basic

' Reference to Microsoft ActiveX Data Objects 2.5 Library
' Reference to Microsoft CDO for Exchange 2000 Library

' Note: It is recommended that all input parameters be validated when they are
' first obtained from the user or user interface.
Sub AddAttachmentToAppt(iAppt As CDO.Appointment, strFilePath As String, strContentType As String, strEncoding As String)

    Dim iBp As CDO.IBodyPart
    Set iBp = iAppt.Attachments.Add

    'Set the fields for the attachment
    Set Flds = iBp.Fields
    Flds.Item("urn:schemas:mailheader:content-type") = strContentType
    Flds.Item("urn:schemas:mailheader:content-transfer-encoding") = strEncoding
    Flds.Update

    'Get the stream interface on the body part
    Set Stm = iBp.GetDecodedContentStream

    'Load the attachment file into the stream and flush
    '  the stream to save it back to the body part
    Stm.LoadFromFile strFilePath
    Stm.Flush

End Sub