Outlook- AppointmentItem and Recurring Appointments

F

Florian Lehner

Hi,

I have got the following problem:
In my application, I want to shift certain Outlook appointments (e.g. "have
all appointments in June 2007 start one hour later").

My code works fine for single appointments and for recurrences starting in
the month selected (e.g. June 2007).

Sadly it doesn't work for recurring appointments if the first element of
this recurrence is not in the month selected (e.g. I want to process June and
the recurrence has started in March).

Here'S some (C#) code:

Application OlApp = new Application();
NameSpace OlNamspace = OlApp.GetNamespace("MAPI");
MAPIFolder AppointmentFolder =
OlNamspace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
AppointmentFolder.Items.IncludeRecurrences = true;
foreach (AppointmentItem app in AppointmentFolder.Items)
{
// do something
}

In my foreach statement, only single AppointmentItem objects are processed,
or starting AppointmentItems of a recurrence. Other Items of recurrences are
simply not found.

My question is, how do I get a handle on those appointments which are part
of a recurrence?

// Die folgende Schleife wird für jeden Termin (AppointmentItem
im betr. Ordner durchgeführt
foreach (AppointmentItem app in AppointmentFolder.Items)
 
S

Sue Mosher [MVP-Outlook]

You're missing a statement to sort by the Start property. That must appear before any IncludeRecurrences statement. Also, if you get recurrences, you must filter the Items collection with a date range. Otherwise, it will be an infinite collection if there are any items with no end time.
 
F

Florian Lehner

Hi,
First of all, thank you for the response. It was great if you gave me an
example in using the Start property, therefore I don't know where this
property belongs to. And which statement can I use for filtering the Items
Collection?

I am asking you these questeions because I do not have any appropriate
documentation on all these interfaces. I have been browsing the msdn, but all
I found was some example code. This example code and the magic help of
IntelliSense is all I that got me so fatrr. If there was some kind of
documentation, some link, virtually anything it woud be very much appreciated.
 
S

Sue Mosher [MVP-Outlook]

All Outlook objects, properties, and methods are fully documented both on MSDN and in the Outlook developer Help file, which can be accessed most easily through VBA's object browser.

For a full discussion of restricting an Items collection by a date range, see http://www.outlookcode.com/article.aspx?id=30

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
 
F

Florian Lehner

Thank you for the help and the links. Now I rewrote my code and I am
experiencing a different problem. The same Appointment is handeled over and
over again:

Application OlApp = new Application();

NameSpace OlNamespace = OlApp.GetNamespace("MAPI");
MAPIFolder AppointmentFolder =
OlNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
Items OlItems = (Items)AppointmentFolder.Items;
OlItems.Sort("[Start]", false);
OlItems.IncludeRecurrences = true;
// changeDT() is a method for transforming a DateTimeValue (e.g. st.FirstDay)
// into a format accepted by the filter method
string itemFilter = "[Start] >= " + changeDT(st.FirstDay) + " and [End] <= "
+ changeDT(st.LastDay);
Items StItems = OlItems.Restrict(itemFilter);
StItems.Sort("[Start]", false);
StItems.IncludeRecurrences = true;

AppointmentItem appItem;
appItem = (AppointmentItem)StItems.GetFirst();
while (appItem != null)
{
// HERE: Always the same appItem is shifted
appItem.Start = appItem.Start.AddHours((values.ShiftValue) *
(-1));
appItem.Save();
}
 
S

Sue Mosher [MVP-Outlook]

I'm no C# programmer, but don't you need a call to StItems.GetNext inside your while loop?

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


Florian Lehner said:
Thank you for the help and the links. Now I rewrote my code and I am
experiencing a different problem. The same Appointment is handeled over and
over again:

Application OlApp = new Application();

NameSpace OlNamespace = OlApp.GetNamespace("MAPI");
MAPIFolder AppointmentFolder =
OlNamespace.GetDefaultFolder(OlDefaultFolders.olFolderCalendar);
Items OlItems = (Items)AppointmentFolder.Items;
OlItems.Sort("[Start]", false);
OlItems.IncludeRecurrences = true;
// changeDT() is a method for transforming a DateTimeValue (e.g. st.FirstDay)
// into a format accepted by the filter method
string itemFilter = "[Start] >= " + changeDT(st.FirstDay) + " and [End] <= "
+ changeDT(st.LastDay);
Items StItems = OlItems.Restrict(itemFilter);
StItems.Sort("[Start]", false);
StItems.IncludeRecurrences = true;

AppointmentItem appItem;
appItem = (AppointmentItem)StItems.GetFirst();
while (appItem != null)
{
// HERE: Always the same appItem is shifted
appItem.Start = appItem.Start.AddHours((values.ShiftValue) *
(-1));
appItem.Save();
}




Sue Mosher said:
All Outlook objects, properties, and methods are fully documented both on MSDN and in the Outlook developer Help file, which can be accessed most easily through VBA's object browser.

For a full discussion of restricting an Items collection by a date range, see http://www.outlookcode.com/article.aspx?id=30

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top