views:

40

answers:

3

Hi together,

I'm using the Outlook-Interop to read some Events from different calendars and show them on a big screen. On my machine everything works fine (Outlook 2010, Win7 x64), but on the client's pc (Outlook2003, Win XP) the program doesn't find all appointments. If I add some checkboxes for debugging the tool finds between 8 and 12 Appointments (12 it should find) and without always 6. I have no idea what's going wrong, so please help me out.

Here's the code:

this.Appointments = new List<AppointmentItem>();

foreach (MAPIFolder folder in this.SelectedCalendars)
{
 foreach (object app in folder.Items)
 {
  if (app is AppointmentItem && ((AppointmentItem)app).Start.Date == DateTime.Now.Date)
  {
   this.Appointments.Add(((AppointmentItem)app));
  }
 }
}

this.Appointments.Sort(
 delegate(AppointmentItem App1, AppointmentItem App2)
 {
  return App1.Start.CompareTo(App2.Start);
 });
A: 

It might be the iterator which is failing for the COM object.

Does it work if you re-write your loop to call GetFirst() and GetNext() explicitly:

object app = folder.Items.GetFirst();
while (app != null)
{
    if (app is AppointmentItem && ((AppointmentItem)app).Start.Date == DateTime.Now.Date)
    {
        this.Appointments.Add(((AppointmentItem)app));
    }
    app = folder.Items.GetNext();
}

You can also try to filter the Items collection on the start date.

var items = folder.Items.Restrict("[Start] < '01/31/2009 00:00 AM' and [Start] >= '01/30/2009 00:00 AM");
Mikael Svenson
Sounds good. I'll give it a try! Could take 1-2 days...
Thomas Spranger
Hm, sry, but this couldn't solve the Problem. I start thinking that it could be a problem with Outlook/Exchange...
Thomas Spranger
Does folder.Items.Count give the same number in 2003 and 2010?
Mikael Svenson
I will check that on the next visit...
Thomas Spranger
The differ on every update. Also with the same Interop. So it's hard to make a comparism
Thomas Spranger
A wild idea. Could it be the date filter which fails? ((AppointmentItem)app).Start.Date == DateTime.Now.DateMaybe one is retrieved without timezone information, so the comparison fails? If you retrieve all appointments for say one month, do you get the correct numbers then?
Mikael Svenson
A: 

Hi Guys, I have some new Information. Got this Exception. Any idea how to handle with?

(I translated from German to English; hope you'll understand ;))

The COM-Object of the type "System.__ComObject" couldn't be changed to the Interfacetype "Microsoft.Office.Interop.AppointmentItem. This procedure couldn't be run, because the Queryinterface-Call to the COM-Component for the interface with IID "{00063033-0000-0000-C000-000000000046}" couldn't be run because of the following error: Interface not supported (Exception _HRESULT:0x80004002 (E_NOINTERFACE)).

Thomas Spranger
Some News: With Office2007 it always delivers the expected result. So it looks like a bug in the Office2003-Interop...
Thomas Spranger
A: 

Make sure you are bound to the 2003 version of the Office Interops which should be forwardly compatible.

LaughingJohn
Already checked. Just for fun I tried also with v14 and got the same results (FYI)
Thomas Spranger