Share via


Publishing an Appointment

Topic Last Modified: 2006-06-11

When you publish an appointment, the appointment is available to others without requiring a response from them. For example, you can publish your company s holidays, charity drives, and upcoming conferences.

You can save a published appointment to a public folder or a file, or you can send a published appointment by e-mail. Published appointments have no attendees.

To publish an appointment

  1. Create an Appointment object.
  2. Set the properties of the appointment.
  3. Create a CalendarMessage object derived from the Appointment object by using the IAppointment.Publish method.
  4. Send the CalendarMessage by using the IMessage methods and save the Appointment object by using the IDataSource.SaveToContainer method.

In the following example, an organizer publishes an appointment to the team alias and saves it to the TeamCalendar public folder.

Example

Visual Basic

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

Sub PublishMeetingToFolder(iAppt As CDO.Appointment, _
                            iMbx As IMailbox, _
                            strTeamCalendarFolderURL As String, _
                            strTeamEmail As String)

    Dim iCalMsg     As CalendarMessage
    Dim Config      As New Configuration
    Dim iPer        As CDO.Person
    Dim Conn        As New ADODB.Connection
    Conn.Provider = "ExOLEDB.DataSource"
            
    'Set the configuration fields
    Set iPer = iMbx
    Config.Fields(cdoSendEmailAddress) = iPer.Email
    Config.Fields(cdoMailboxURL) = iMbx.BaseFolder
    Config.Fields.Update
    
    With iAppt
        Set .Configuration = Config
        'Publish the appointment
        
        ' Get CalendarMessage and send to the team.
        Set iCalMsg = .Publish
        iCalMsg.Message.To = strTeamEmail
        iCalMsg.Message.Send

        'Save the appointment to a public folder
        Conn.Open strTeamCalendarFolderURL
        .DataSource.SaveToContainer strTeamCalendarFolderURL, Conn

    End With

End Sub

C++

/*
 Assume that the following paths are in your
 INCLUDE path.
 %CommonProgramFiles%\system\ado
 %CommonProgramFiles%\microsoft shared\cdo
*/

#import <msado15.dll> no_namespace
#import <cdoex.dll> no_namespace  
#include <iostream.h>

void publishAppointmentToFolder( 
                     const IAppointmentPtr& iAppt, 
                     const IMailboxPtr& iMbx,
                     const bstr_t& strTeamCalendarFolderURL,
                     const bstr_t& strTeamEmail) 
{


   ICalendarMessagePtr iCalMsg;
   IConfigurationPtr   iConf(__uuidof(Configuration));
   IPersonPtr          iPer;
   _ConnectionPtr      Conn(__uuidof(Connection));

   Conn->Provider = "ExOLEDB.DataSource";

   try {
      iPer = iMbx;
   }
   catch(_com_error e ) {
      cerr << "Invalid or unbound Person object reference passed. " << endl;
      _com_issue_error(E_INVALIDARG);
   }

   iConf->Fields->Item[cdoSendEmailAddress]->Value = variant_t(iPer->Email);
   iConf->Fields->Item[cdoMailboxURL]->Value = variant_t(iMbx->BaseFolder);
   iConf->Fields->Update();

   iAppt->Configuration = iConf;

   try {
      iCalMsg = iAppt->Publish();    
      iCalMsg->Message->To = strTeamEmail;
      iCalMsg->Message->Send();

      // Save the appointment to a public folder
   }
   catch(_com_error e) {
      cerr << "Failed to send e-mail to " << strTeamEmail << endl;
      throw e;
   }

   try {
       Conn->Open(strTeamCalendarFolderURL, bstr_t(), bstr_t(), -1);
      iAppt->DataSource->SaveToContainer(strTeamCalendarFolderURL,
                              Conn,
                              adModeReadWrite,
                              adCreateNonCollection,
                              adOpenSource,
                              bstr_t(),
                              bstr_t());
   }
   catch(_com_error e) {
      cerr << "Failed to save appointment to folder at URL: " << strTeamCalendarFolderURL << endl;
      throw e;
   }

}