将ics文件导入Outlook.AppointmentItem

时间:2010-03-04 14:06:08

标签: outlook-addin outlook-2007 icalendar appointment

我有一个Outlook 2007加载项,它试图将ics文件导入Outlook.AppointmentItem对象,以便我可以读取有关某些约会的属性。目前我无法将ics读回内存。关于我做错了什么的任何建议。

Outlook.Application app = new Outlook.Application();
var item = app.Session.OpenSharedItem("C:\\meeting.ics") as Outlook.AppointmentItem;
string meetingBody = item.Body; //<--*my item is null*

由于

3 个答案:

答案 0 :(得分:1)

我认为问题是由于AppointmentItemMeetingItem是不同的类,所以你不能直接将一个转换为另一个。您可以尝试以下方法并检查它是否有效吗?

var item = app.Session.OpenSharedItem(@"C:\meeting.ics") as Outlook.AppointmentItem;

答案 1 :(得分:1)

这可能是因为此ics文件仅提供会议项目而非约会项目。据我所知,你可以尝试使用如下代码,

Outlook.MeetingItem item = app.Session.OpenSharedItem(@"C:\SomeMeeting.ics") as Outlook.MeetingItem;

如果您对此有任何疑虑,请随时跟进。

http://social.msdn.microsoft.com/Forums/en-GB/vsto/thread/f98bfa75-a995-403e-a3fc-5be3a37511d7

答案 2 :(得分:1)

只需检查其类型

            Set attObj = ns.OpenSharedItem(strFilename)                

            Select Case TypeName(attObj)
                Case "MeetingItem"
                    Dim miNewMeetingItem As Outlook.MeetingItem
                    Set miNewMeetingItem = attObj
                    ...
                Case "AppointmentItem"
                    Dim miNewAppointmentItem As Outlook.AppointmentItem
                    Set miNewAppointmentItem = attObj
                    ...
                Case Else
                    Dim miNew As Outlook.MailItem
                    Set miNew = attObj
                    ...
            End Select

            Set attObj = Nothing