.net 从多个帐户获取日历约会
我目前正在创建Outlook加载项,并使用下面的功能从Outlook中连接的所有帐户获取所有日历约会.net 从多个帐户获取日历约会,.net,exchange-server,outlook-addin,.net,Exchange Server,Outlook Addin,我目前正在创建Outlook加载项,并使用下面的功能从Outlook中连接的所有帐户获取所有日历约会 private List<Outlook.MAPIFolder> _calendarsFolder = new List<Outlook.MAPIFolder>(); private List<Outlook.Items> _calendarsItems = new List<Outlook.Items>(); private void GetC
private List<Outlook.MAPIFolder> _calendarsFolder = new List<Outlook.MAPIFolder>();
private List<Outlook.Items> _calendarsItems = new List<Outlook.Items>();
private void GetCalendarsItems(object sender, EventArgs e)
{
Outlook.NameSpace session = Globals.ThisAddIn.Application.Session;
Outlook.Accounts accounts = session.Accounts;
foreach (Outlook.Account account in accounts)
{
Outlook.Recipient recipient = session.CreateRecipient(account.DisplayName);
Outlook.MAPIFolder calendar = null;
try
{
calendar = session.GetSharedDefaultFolder(recipient, Outlook.OlDefaultFolders.olFolderCalendar);
}
catch (Exception)
{
continue;
}
if (calendar != null)
{
var calendarItems = calendar.Items;
AttachEvents(calendarItems);
_calendarsFolder.Add(calendar);
_calendarsItems.Add(calendarItems);
foreach (Outlook.AppointmentItem item in calendarItems)
{
if (Select_T_OutlookEvent_Exists(item.GlobalAppointmentID)) continue;
var outlookEvent = new T_OutlookEvent()
{
Id = item.GlobalAppointmentID,
Title = item.Subject,
Description = item.Body,
Location = item.Location,
Organizer = item.GetOrganizer().Name
};
Insert_T_OutlookEvent(outlookEvent);
}
}
}
}
问题是我只能从一个连接到Exchange的帐户获得约会,它也是主要帐户。GetSharedDefaultFolder函数调用COMException时引发异常:由于注册表或安装问题,操作失败。重新启动Outlook并重试。如果问题仍然存在,请为所有其他帐户重新安装:一个连接到Exchange的帐户,另两个未连接
提前感谢您的帮助 GetSharedDefaultFolder用于委派方案,不允许您访问所有本地/个人日历。相反,通过NameSpace.Stores循环并使用Store.GetDefaultFolder获取每个已配置帐户/存储的日历。哪行代码抛出了COMException错误?另外,为什么要使用GetSharedDefaultFolder?这是用于委派场景的。相反,在NameSpace.Stores中循环并使用Store.GetDefaultFolderI在调用GetSharedDefaultFolder时获取异常。我不明白GetSharedDefaultFolder是用于委派场景的,我将尝试使用商店,非常感谢Eric!不客气,我已经添加了我的评论作为回答