连接到Outlook日历中使用互操作的C# [英] Connect to Outlook calendar from C# using Interop
问题描述
好吧,我尝试使用下面的代码连接到从C#Outlook日历:
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.
我猜日历ID是比它的名字以外的东西。
I'm guessing the calendars ID is something other than it's name.
我在做什么错了?
另外,我使用C#4在.NET 4中和Outlook 2010。
Also, I'm using C#4 with .Net 4 and Outlook 2010.
推荐答案
是MAPI命名空间中两个日历?如果你遍历命名空间,看看其他的有一个日历:
Are both calendars in the MAPI namespace? What if you loop through the namespaces to see if other ones have a calendar:
Outlook.Application msOutlook = new Outlook.Application();
Outlook.NameSpace session = msOutlook.Session;
Outlook.Stores stores = session.Stores;
foreach (Outlook.Store store in stores)
{
Outlook.MAPIFolder folder = store.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);
MessageBox.Show(folder.Name);
}
这篇关于连接到Outlook日历中使用互操作的C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!