Importing ics file to an Outlook.AppointmentItem
Asked Answered
F

3

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

Firmin answered 4/3, 2010 at 14:6 Comment(2)
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.Sulfamerazine
@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."Hartle
M
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

Methylamine answered 4/3, 2010 at 14:6 Comment(0)
T
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;
Teeterboard answered 8/12, 2011 at 9:27 Comment(0)
A
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
Ancestry answered 9/1, 2015 at 17:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.