Rick Make
Rick Make

Reputation: 521

Importing ics file to an Outlook.AppointmentItem

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

Upvotes: 14

Views: 1608

Answers (3)

R0man
R0man

Reputation: 41

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

Upvotes: 1

John Peter
John Peter

Reputation: 2928

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

Upvotes: 1

Alberto
Alberto

Reputation: 543

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;

Upvotes: 1

Related Questions