Read Appointment items in a shared calendar

W

warbornster

I want to create a program in c# that can read my appointmentitems in
all shared calendars, and detect the user of that item. If its possible
to read the shared calendar, can I read the user, or do I have to
create a new field or something ?
 
K

Ken Slovak - [MVP - Outlook]

What do you mean by "detect the user"?

You can use NameSpace.GetSharedDefaultFolder(olFolderCalendar) to get the
default Calendar folders for any mailboxes where you have the appropriate
permissions. If the shared mailbox is loaded as part of your Outlook profile
you can iterate the NameSpace.Folders collection to hit each loaded shared
mailbox and from there dig down through the various Folders collections to
find any folder of any type. Once you have a folder you get its Items
collection.

The Organizer is who created an item. If something changes in an appointment
you can use a lower level API such as CDO 1.21 or Extended MAPI or
Redemption (www.dimastr.com/redemption) to read the PR_LAST_MODIFIER_NAME
property (0x3FFA001E ) which is a PT_STRING8 property that gives the name of
the last person to modify the item. That's not exposed in the Outlook object
model.
 
W

warbornster

Could you please show a bit code about the iteration? I guess it has
something to do with foreach, but not too sure how to use it.
 
K

Ken Slovak - [MVP - Outlook]

Please put some of the preceding thread in your posts, it makes it easier to
follow a thread.

foreach is a very slow loop, if you have a lot of items it will take a long
time. A plain for loop is faster.

You didn't answer my question about what you mean by "detect the user". And
what version of Outlook are you programming against?

For GetSharedDefaultFolder you need to supply a Recipient object as well as
a folder type. The Recipient is the user who's calendar is being opened.
Assuming that a NameSpace object (oNS) has already been instantiated C# code
to iterate a calendar folder's Items collection would look something like
this:

Outlook.Recipient oRecip = (Outlook.Recipient)oNS.CreateRecipient("Joe
Foobar");

Outlook.MAPIFolder oFolder =
(Outlook.MAPIFolder)oNS.GetSharedDefaultFolder(oRecip,
Outlook.OlDefaultFolders.olFolderCalendar);

Outlook.Items colItems = (Outlook.Items)oFolder.Items;

int I = colItems.Count;

Outlook.AppointmentItem oItem = null;

for(int J = 1; J <= I; J++)
{
oItem = (Outlook.AppointmentItem)colItems[J];
//whatever
}

Of course this code doesn't check to verify that a valid Recipient was
created and does no error trapping at all. It doesn't check to make sure
that the item is actually an AppointmentItem. In real life there'd be a
bunch of try{ } catch{ } blocks and so on.
 
W

warbornster

You didn't answer my question about what you mean by "detect the user". And
what version of Outlook are you programming against?

I meant that I want to see what users there is in the "users list" or
whatever it is. When I add a user to the recipients collection, I would
not need to use the whole name. For example, If I in outlook have the
main user called Robert Andersson, I would just have to use Recipient
Rec = (Recipient)oNS.CreateRecipient("Robert"). If I would like to see
the name for this user, I could use Rec.Name and it would display
Robert Andersson. So when I saw that this was possible I was sure that
this names must be stored somewhere, and thats what I need to find out
how to get those names. And I use Outlook 2003.
 
K

Ken Slovak - [MVP - Outlook]

You can't get the shared calendars unless you know the alias names of the
available recipients. Plus you would need permissions to open their
calendars.

You can read the Global Address List, which is one of your AddressLists.
Open the AddressLists collection and get the GAL AddressList. You can then
iterate that list and get the names of everyone available. You can then try
opening each calendar using the name you just got and creating a Recipient
object for that name. That of course doesn't guarantee that you will
succeed, you need permissions, so be prepared to handle errors when you try
to open the folder using GetSharedDefaultFolder.
 
W

warbornster

You can't get the shared calendars unless you know the alias names of the
available recipients. Plus you would need permissions to open their
calendars.

You can read the Global Address List, which is one of your AddressLists.
Open the AddressLists collection and get the GAL AddressList. You can then
iterate that list and get the names of everyone available. You can then try
opening each calendar using the name you just got and creating a Recipient
object for that name. That of course doesn't guarantee that you will
succeed, you need permissions, so be prepared to handle errors when you try
to open the folder using GetSharedDefaultFolder.


I already have the permission I need from those who are suppost to
share their calendar. But I looked up that GAL in outlook and there was
one address which doesent allow me to access, can I comehow use some
kind of exception when Im not allowed by the other user ? And by the
way, is it possible not to get those security messages from outlook
when I try to read the items? Because if not, I guess that there will
be A LOT of messages when Im trying to read all the appointment items
from like 10-20 addresses.
 
K

Ken Slovak - [MVP - Outlook]

You always have to handle exceptions. Your exception handler should be able
to handle cases where you can't get access when you create the Recipient
object and attempt to use GetSharedDefaultFolder.

For the security and your options look at
http://www.outlookcode.com/d/sec.htm
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top