2010-03-04 44 views
14

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

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* 

感谢

+0

是否ICS文件已经UNIX或Windows结束行字符?当我试图做类似的事时,我遇到了一个问题 - 因为我试图导入时的ics文件是由PHP在unix平台上生成的 - 将行尾字符更改为Windows似乎有所帮助。 – alshapton 2011-11-18 10:59:44

+0

@alshapton ... ICS兼容文件REQUIRE CRLF的行尾 - 请参阅RFC 5545,第3.1节:“与iCalendar对象关联的内容信息使用类似于[RFC2425]定义的语法格式化。 ,内容信息由CRLF分隔的内容行组成。“ – 2011-12-01 17:00:59

回答

1

我认为这个问题是由于这样的事实:AppointmentItemMeetingItem是不同类的,所以你不能直接转换彼此。你可以尝试以下方法并检查它是否有效?

var item = app.Session.OpenSharedItem(@"C:\meeting.ics") as Outlook.AppointmentItem; 
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