Programmatically open another user's calendar

S

Stephan Steiner

Hi

In our organization, we share all our calendars, so that if someone isn't
around, you can open their calendar in your Outlook (File - Open - Other
User's Folder - then select the calendar and press OK) and find out what
they're doing and when they'll be back.

Now I'd like to open a calendar via an add in (imagine a button in a
contact, but eventually it'll become much more advanced). Is there a way to
do it, and if so, how? Any sample code would be much appreciated.

Stephan
 
K

Ken Slovak - [MVP - Outlook]

The NameSpace.GetSharedDefaultFolder method is what is generally used if the
shared folder is a default folder in the other user's mailbox. That method
takes a Recipient as the first argument, that would be the user whose folder
you want to open. The second argument is the type of folder from the
OlDefaultFolders enum.

If the folder isn't a default folder you would have to have it opened as
part of the user's profile or use CDO 1.21 code to open it as a CDO Folder
object. There's code for that at www.cdolive.com/cdo5.htm.
 
S

Stephan Steiner

Ken
The NameSpace.GetSharedDefaultFolder method is what is generally used if the
shared folder is a default folder in the other user's mailbox. That method
takes a Recipient as the first argument, that would be the user whose folder
you want to open. The second argument is the type of folder from the
OlDefaultFolders enum.

Thanks, this works as a charm (except for the fact that Outlook now asks me
to authorize access to its data - is there any way around that?). But more
importantly, I think I worded my question wrong.. I don't want my program to
read anything from the folder, rather I'd just like to display that folder
as Outlook would if you go through the (File - Open - Other user's folder)
menu. Is there a way to do this?

Stephan
 
S

Stephan Steiner

Ken

I figured it out, thanks to google groups (it's amazing how a completely
unrelated subject sometimes contains just what you need to find the
solution). Anyway, if somebody else is interested, here's how I did it:

Outlook.Recipient rec = ns.CreateRecipient("Gerber, Daniel");
bool valid = rec.Resolve();
try
{
ns = applicationObject.GetNamespace("MAPI");
folder = ns.GetSharedDefaultFolder(rec,
Outlook.OlDefaultFolders.olFolderCalendar); // get the folder I want to open
Outlook.Explorer newExplorer = applicationObject.Explorers.Add(folder,
Outlook.OlFolderDisplayMode.olFolderDisplayFolderOnly); // open folder in
new window
newExplorer.Activate(); // show new window
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}

Regards
Stephan
 

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