如何获取Outlook中所有可用日历的列表?
我有两个用户登录,我可以使用以下代码找到它们:
var needToShowPopup = true;
try {
needToShowPopup = !localStorage.getItem("shown-popup");
} catch (e) {
}
if (needToShowPopup) {
// We haven't shown it yet
setTimeout(function() {
// ----show the div here ----
// Flag we've shown it (you might do this only when they click the [x])
try {
localStorage.setItem("shown-popup", "yes");
} catch (e) {
}
}, 2000);
}
我现在如何获得每个用户的日历列表?或者至少获得混合在一起的所有日历的列表?
答案 0 :(得分:1)
You can use next code for solve this problem:
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.NameSpace session = Globals.ThisAddIn.Application.Session;
Outlook.Accounts accounts = session.Accounts;
List<Outlook.MAPIFolder> calendars = new List<Outlook.MAPIFolder>();
foreach (Outlook.Account account in accounts)
{
Outlook.Recipient recipient = session.CreateRecipient(account.DisplayName);
Outlook.MAPIFolder calendar = session.GetSharedDefaultFolder(recipient, Outlook.OlDefaultFolders.olFolderCalendar);
if (calendar != null)
{
calendars.Add(calendar);
}
}
}
答案 1 :(得分:0)
建议答案的策略效果很好。我尝试了类似的解决方案来为特定用户获取正确的日历,如下所示:
var session = Application.Session;
var accounts = session.Accounts;
//get default calendar
var calendar = (MSOutlook.Folder)session.GetDefaultFolder(MSOutlook.OlDefaultFolders.olFolderCalendar);
//get calendar for specific user
foreach (MSOutlook.Account account in accounts)
{
if (string.Equals(account.SmtpAddress, "someone@somewhere.com", StringComparison.InvariantCultureIgnoreCase))
{
var recipient = session.CreateRecipient(account.DisplayName);
calendar = (MSOutlook.Folder)session.GetSharedDefaultFolder(recipient,
MSOutlook.OlDefaultFolders.olFolderCalendar);
break;
}
}
Marshal.ReleaseComObject(session);
Marshal.ReleaseComObject(accounts);