使用 Interop 从 C# 连接到 Outlook 日历
好的,我尝试使用以下代码从 C# 连接到 Outlook 日历:
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.Application msOutlook = new Outlook.Application();
Outlook.NameSpace ns = msOutlook.GetNamespace("MAPI");
Outlook.MAPIFolder folder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
foreach (Outlook.MAPIFolder subfolder in folder.Folders)
{
MessageBox.Show(subfolder.Name);
}
但是,尽管有两个日历,上面的代码片段看不到任何日历!
我想我可能对下面的代码有更多的运气:
Outlook.MAPIFolder folder = ns.GetFolderFromID("CalendarName", Type.Missing);
但这引发了以下异常:
无法打开该项目。再试一次。
我猜日历 ID 不是它的名称。
我做错了什么?
另外,我将 C#4 与 .Net 4 和 Outlook 2010 一起使用。
Ok I am trying to connect to an Outlook calendar from C# using the following code:
using Outlook = Microsoft.Office.Interop.Outlook;
Outlook.Application msOutlook = new Outlook.Application();
Outlook.NameSpace ns = msOutlook.GetNamespace("MAPI");
Outlook.MAPIFolder folder = ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
foreach (Outlook.MAPIFolder subfolder in folder.Folders)
{
MessageBox.Show(subfolder.Name);
}
However, despite having two Calendars, the piece of code above doesn't see any!
I'm thinking I may have more luck with the below code:
Outlook.MAPIFolder folder = ns.GetFolderFromID("CalendarName", Type.Missing);
But this is throwing the the following exception:
Could not open the item. Try again.
I'm guessing the calendars ID is something other than it's name.
What am I doing wrong?
Also, I'm using C#4 with .Net 4 and Outlook 2010.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
两个日历都在 MAPI 命名空间中吗?如果您循环遍历命名空间以查看其他命名空间是否有日历会怎样:
Are both calendars in the MAPI namespace? What if you loop through the namespaces to see if other ones have a calendar: