【发布时间】:2017-11-24 21:15:54
【问题描述】:
我正在尝试从一些共享交换日历中获取一些日历约会。第一次访问工作正常。但是当我再次调用该函数时。我得到一个超出范围的错误。
当我将所有全局变量设置为临时变量时,我收到错误“无法打开日历”。
如何创建一个 Outlook 实例然后再次关闭它。以便您可以在需要时创建一个新的?
谢谢
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);
}
}
}
}
}
【问题讨论】:
标签: c# outlook calendar exchange-server