I'm trying to get some calendar appointments from some shared exchange calendars. The first access works fine. But when I call the function again. I get an out of range error.
When I make all global vars to temp var then the I get error "Could not open calendar".
How is it possible to create an Outlook instance and then close it again. So that you can create a new one when you need it?
Thanks
Outlook.Folder _folder = null;
Outlook.Application oApp;
Outlook.Recipient recip;
private void GetCalendar(string mailAddressOfCalendar)
{
if (_folder != null)
{
ForceUpdateAddOnCalaendar(_folder);
}
else
{
oApp = new Outlook.Application();
Outlook.AddressEntry addrEntry = oApp.Session.CurrentUser.AddressEntry;
if (addrEntry.Type == "EX")
{
recip = oApp.Session.CreateRecipient(mailAddressOfCalendar);
if (recip.Resolve())
{
try
{
if (_folder == null)
{
_folder =
oApp.Session.GetSharedDefaultFolder(
recip, Outlook.OlDefaultFolders.olFolderCalendar)
as Outlook.Folder;
}
ForceUpdateAddOnCalaendar(_folder);
}
catch
{
MessageBox.Show("Could not open calendar",
"GetSharedDefaultFolder Example",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
}