14

I have an Outlook 2007 add-in that is trying to import ics files into Outlook.AppointmentItem objects so that I can read attributes about certain appointments. Currently I am not able to read the ics back into memory. Any suggestions on what I am doing wrong.

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*

Thanks

Dave L.
  • 9,595
  • 7
  • 43
  • 69
Rick Make
  • 521
  • 2
  • 6
  • 14
  • Does the ICS file have unix or windows end-of-line characters ? I had a problem when I was trying to do something similar - since the ics file when I was trying to import was produced by PHP on a unix platform - changing the end-of-line characters to Windows seemed to help. – alshapton Nov 18 '11 at 10:59
  • @alshapton... ICS-compatible files REQUIRE line-endings of CRLF -- see RFC 5545, sec 3.1: "The content information associated with an iCalendar object is formatted using a syntax similar to that defined by [RFC2425]. That is, the content information consists of CRLF-separated content lines." – Chris J Dec 01 '11 at 17:00

3 Answers3

1

It may be because that this ics file just presents a meeting item rather an appointment item. As far as I know, you could try to use code as below,

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

If you have any concern for this, please feel free to follow up.

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

John Peter
  • 2,870
  • 3
  • 27
  • 46
1

Just check its type

            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
R0man
  • 41
  • 2
1

I think the problem is due to the fact that AppointmentItem and MeetingItem are different classes so you cannot convert one to another directly. Could you try the following and check if it works?

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