Marian Aldenhövel
Marian Aldenhövel

Reputation: 727

Outlook access shared calendar

I am building an application in Embarcadero Delphi that amongst other things wants to read appointments from outlook calendars shared with the current user.

My problem is a lack of understanding where to find these in the folder-structure.

On my desktop I use Outlook 2010 (14.0.7188.5002 32-Bit) connected to an exchange server. I am able to add calendars shared by colleagues to my calendar-view in Outlook:

Screenshot from Outlook, names redacted

I can see selected information about their appointments, mainly whether they are free or booked. Exactly what my external tool wants to know.

Now I would like to access those calendars via the Outlook object model.

(I apologize for posting Delphi-Code, but it is mostly going straight to the imported TLB which in other places works as advertised)

I tried using GetSharedDefaultFolder() like this:

Recipient := FOutlook.NameSpace.CreateRecipient('[email protected]');
Recipient.Resolve;
SharedFolder := FOutlook.Namespace.GetSharedDefaultFolder(Recipient, olFolderCalendar);

But this unfortunately fails on the call to GetSharedDefaultFolder(). The Recipient is correct, it resolves fine. The error thrown (as Delphi exception) is:

EOleException - Der versuchte Vorgang konnte nicht ausgeführt werden. Ein Objekt wurde nicht gefunden

This translates back into english as: "The attempted action could not be completed. An object was not found".

I would appreciate any input on how to access the same information Outlook is showing me in the UI when I select a shared calendar, only via the object model.

Thanks in advance for your time, Marian

Upvotes: 0

Views: 911

Answers (1)

Marian Aldenhövel
Marian Aldenhövel

Reputation: 727

I am guilty of failing to show my whole code, the real code and complete code.

@nitons comment and specifically the claim in the linked answer that a non-shared calendar would simply show up empty, prompted me to play around more.

I was indeed missing the call to Recipient.Resolve. My real code is iterating over the members of distribution list, but I did not think that was important, because it was working. So in fact I was not creating a new Recipient and resolving it, but I had:

for i := 1 to DistList.MemberCount do
  begin
    Recipient := DistList.GetMember(i);
    if not Recipient.Resolved 
      then Recipient.Resolve;
    Folder := FOutlook.NameSpace.GetSharedDefaultFolder(Recipient, olFolderCalendar);
    // ...
  end;

This fails as described. I made the call to Resolve unconditional but still failed.

What works for me is creating a new Recipient from the one returned by DistList.GetMemberlike this:

Recipient := DistList.GetMember(i);
Recipient := FOutlook.NameSpace.CreateRecipient(Recipient.Address);
Recipient.Resolve;
Folder := FOutlook.NameSpace.GetSharedDefaultFolder(Recipient, olFolderCalendar);

This works nicely. So does replacing the access to the Calendar with a call to Recipient.FreeBusy.

Thank you very much, Dmitry and niton, You have helped me a lot.

Upvotes: 0

Related Questions