View Single Post
  #8  
Old November 19th 06, 01:39 AM posted to microsoft.public.outlook.program_addins
Tony Gravagno
external usenet poster
 
Posts: 12
Default Programmatically finding calendar folders for Exchange server users

"Dmitry Streblechenko" wrote:
Are you sure about that? Application.CreateItem() creates new item in the
corresponding default fodler, which would be current user's Calendar folder
in your case.
How did you call MAPIFolder.Items.Add? It eother takes a message class
(string, in your case "IPM.Appointment") or one of the OlItemType enums
(olAppointmentItem in your case).

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool



I did my homework and as (almost) always Dmitry, you're right.

Once again I was confused. For anyone else trying to do this, here is
the code for creating an appointment in different folders, depending
on whether it's the local PST (same as local user on Exchange), or a
shared folder. I've removed all error handling and hacked up the code
to make it a little more explanatory - this will not run as-is but
almost. I recommend anyone else who's doing this definitely handle
all issues, and be sure to close, displose, and null all objects where
possible.

PIA.Outlook.Recipient olRecipient =
olns.CreateRecipient(sharename);
// resolution not necessary with correct name
// casing on name doesn't matter.

if (olRecipient != null)
{
olRemoteCalendar =
olns.GetSharedDefaultFolder(
olRecipient,
PIA.Outlook.OlDefaultFolders.olFolderCalendar);
// handle errors!
}
if (olRemoteCalendar == null)
// local PST
olAppointmentItem =
(PIA.Outlook.AppointmentItem)
olapp.CreateItem(
PIA.Outlook.OlItemType.olAppointmentItem);
// handle errors!
} else {
olAppointmentItem =
(PIA.Outlook.AppointmentItem)
olRemoteCalendar.Items.Add(
Microsoft.Office.Interop.
Outlook.OlItemType.olAppointmentItem);
// that line split for readability
// did I mention you must handle errors?!
}

At this point we have a good olAppointmentItem, the .Save method will
save it wherever it belongs. (Ignore my misunderstanding one posting
up in this thread.)

Yes, I could have organized differently depending on whether I had a
shared folder name or not. Next time.

People in these forums have given so much to me with their time and
advice, I hope this gives back just a bit.

Tony Gravagno
Nebula Research and Development
TG@ remove.anti-spam.mungingNebula-RnD.com
Ads