0

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('bernie@someplace.com');
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

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Marian Aldenhövel
  • 677
  • 1
  • 6
  • 24
  • Seeing Free/Busy does not indicate shared. If [not shared](https://stackoverflow.com/questions/34202507/how-to-get-free-busy-information-of-not-shared-appointment-attendee-in-net). If you only need Free/Busy information, try [Recipient.FreeBusy](https://msdn.microsoft.com/en-us/vba/outlook-vba/articles/recipient-freebusy-method-outlook). Note: My VBA experience is email addresses always resolve, use a name instead. – niton Jun 22 '18 at 12:13
  • If you look at the Recipient.Address property, is it EX or SMTP type address? – Dmitry Streblechenko Jun 22 '18 at 13:49
  • > Seeing Free/Busy does not indicate shared. I have added the calendars I blacked out in my screenshot by doing "Kalender hinzufügen" -> "Freigegebenen Kalender öffnen". Which I translate back as "Add Calendar" -> "Open shared calendar". That is my only indication that the calendars I am interested in have been shared with me. I have replaced access to the shared calendar with a call to Recipient.FreeBusy, but that gives me the same Element not found error. Does that imply that the Recipient is not found, even though it resolves fine, and it's not even a problem with the calendar? – Marian Aldenhövel Jun 25 '18 at 08:10
  • Recipient.Address gives me the address in "name.firstname@domain.tld" format. Recipient.AddressEntry.Type says "SMTP". I have tried your suggestion of creating the recipient by name instead of Address, but in that form it does not resolve. – Marian Aldenhövel Jun 25 '18 at 08:11
  • 1
    With the failure to resolve a name you are likely missing the create recipient step. This is the process in VBA. https://stackoverflow.com/a/5626512/1571407 Note your comments need an @ before the username to be sent to a specific user. The post owner is always notified. – niton Jun 25 '18 at 11:07

1 Answers1

0

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.

Marian Aldenhövel
  • 677
  • 1
  • 6
  • 24