OutlookSession and Appointments reading slow??

  • Thread starter Thread starter juvi
  • Start date Start date
J

juvi

hello,

I have the following code to read outlook appointments. I am only interested
in the next/upcoming appointment. Is there a more performance-friendly way to
do this?

try
{
OutlookSession session = new OutlookSession();
AppointmentFolder appointments = session.Appointments;

appCount = 0;

foreach (Appointment a in appointments.Items)
{
if (a.Location != "")
{
s = a.Start.ToShortDateString() + ": " + a.Subject +
" (" + a.Location + ")";
}
else
{
s = a.Start.ToShortDateString() + ": " + a.Subject;
}

if (a.Start > DateTime.Now)
{
appCount = 1;
goto NextTask;
}
}

NextTask:

if (appCount == 0)
goto NoAppointments;

foreach (Appointment a in appointments.Items)
{
s = a.Start.ToShortTimeString() + " - " +
a.End.ToShortTimeString();
}


NoAppointments:
if (appCount == 0)
{

}

session.Dispose();
appointments.Dispose();
}
catch
{

}
 
Using the Microsoft.WindowsMobile.Status.SystemState.CalendarNextAppointment
will return just the next appointment item.

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility
 
Thank you for your reply. That is true, but it will only work if the next
appointment is within 24h - else there comes a Null Reference Exception.

Is there no solution for this problem?

thx
juvi
 
In that case you would be better using the Restrict method on the
Appointments collection and read the first item returned e.g. something like
this

AppointmentCollection matches = session.Appointments.Items.Restrict("[Start]
" + DateTime.Now.ToString("dd/MM/yyyy") );

Peter

--
Peter Foot
Microsoft Device Application Development MVP
peterfoot.net | appamundi.com | inthehand.com
APPA Mundi Ltd - software solutions for a mobile world
In The Hand Ltd - .NET Components for Mobility
 
Back
Top