Search code examples
c++visual-c++outlookmapioutlook-object-model

C++ Outlook Object Model get shared calendar folder


I want to user GetCalendarExporter() on contact folder of shared calendar.

I have written code which I feel will give only default calendar folder(i.e. Owner's calendar folder). I want Shared(Delegated) Calendar folder object/pointer. Any idea how to do that?

As of now my code is like:


CComPtr<Olk::_NameSpace> spNameSpace = spApplication->GetNamespace(L"MAPI");

Olk::MAPIFolderPtr spCalFolder = spNameSpace->GetDefaultFolder(Olk::olFolderCalendar);

spCalFolder->GetCalendarExporter();


Solution

  • You need to use the NameSpace.GetSharedDefaultFolder method which returns a Folder object that represents the specified default folder for the specified user. This method is used in a delegation scenario, where one user has delegated access to another user for one or more of their default folders (for example, their shared Calendar folder).

    Sub ResolveName() 
     Dim myNamespace As Outlook.NameSpace 
     Dim myRecipient As Outlook.Recipient 
     Dim CalendarFolder As Outlook.Folder 
     Set myNamespace = Application.GetNamespace("MAPI") 
     Set myRecipient = myNamespace.CreateRecipient("Eugene Astafiev") 
     myRecipient.Resolve 
     If myRecipient.Resolved Then 
       Call ShowCalendar(myNamespace, myRecipient) 
     End If 
    End Sub 
     
    Sub ShowCalendar(myNamespace, myRecipient) 
     Dim CalendarFolder As Outlook.Folder 
     Set CalendarFolder = myNamespace.GetSharedDefaultFolder(myRecipient, olFolderCalendar) 
     CalendarFolder.Display 
    End Sub