How Can I Flush Outlook Cache?

T

Tadwick

I'm finding that retrieving appointments from the same recipient over and
over is preventing IncludeRecurrences from working properly. Instead of
individual occurences I keep getting the master. I've confirmed this by
retrieving appointments from a recipient that hasn't been queried for a while
and I get the individual occurrences. This only happens in code - when I
view the recipient's calendar the recurring appointments show as expected. I
am sorting items and setting IncludeRecurrences = True etc so this behaviour
is quite frustrating.

Is this a phenomenon that has been noted elsewhere? I have only found an
archived post from this newsgroup back in 1994 where Ken Slovak alluded to
strange behaviour all these lines.

see http://www.pcreview.co.uk/forums/thread-1838616.php

Can I solve this by flushing the cache and, if so, how do I do this and how
often do you think I need to do this?

Thanks, Tad
 
T

Tadwick

Hi Ken,

Thanks for the reply. My problem was defining the appointments in VBA as
Outlook.Appointment instead of object. That fixed the issue in VBA.
However, the problem that caused this is that I'm trying to convert my VBA
code to C# and I was getting mixed up with how appointment items are defined
in the two languages. There is another article
(http://support.microsoft.com/?kbid=310265) that discusses C# and recurrences
but I'm still getting the master appt for recurring appointments. This only
happens to other users' folder, not my own. My code is below. Have you
tried this in dot net 2.0?

Thanks, Tad

public void GetAppointments(String recipient, String entryid)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");

//create recipient
Outlook.Recipient oRcp = oNS.CreateRecipient(recipient);

//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
{
Outlook.Items oItms = (Outlook.Items)oFdr.Items;

strFilter = "([End] > \'September 1, 2006 12:00 AM\' AND [Start] <=
\'March 1, 2007 12:00 AM\')";

Outlook.Items oApps = oItms.Restrict(strFilter);
oApps.Sort("[Start]",false);
oApps.IncludeRecurrences = true;//blnIncludeRecurrences;

Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oApps.GetFirst();

while (oAppt != null)
{
MessageBox.Show("Subject = " + oAppt.Subject + " Start = " +
oAppt.Start.ToString("MMM dd, yyyy HH:mm"));
oAppt = (Outlook.AppointmentItem)oApps.GetNext();
}
}
}
 
K

Ken Slovak - [MVP - Outlook]

Do you have sufficient permissions for accessing that mailbox and its
Calendar folder?

I did a quickie console app using C# and VS2005, Framework 2.0 running on
Outlook 2007.

I hard coded the mailbox recipient and since that Outlook setup has multiple
profiles I had to select an Exchange profile on startup. Other than that it
ran seamlessly and without errors and displayed one at a time all the
appointments.

I created 1 recurring appointment in my sales mailbox, but the principle
should apply even if the folder has many different appointments, mixing
recurring and non-recurring.

The Outlook profile used was my dog's profile against his mailbox on my
Exchange server, so Outlook was logged in as my dog. That profile was able
to access my sales mailbox, but my dog has permissions on that mailbox (he's
my sales manager).

Here's the code I used (appropriate references were set of course):

using System;
using System.Collections.Generic;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;

namespace ConsoleApplication1
{
public partial class Program
{
static void Main(string[] args)
{
bool Foobar = false;
Foobar = GetAppointments();
}

private static bool GetAppointments()
{

Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
Outlook.AppointmentItem oAppt = null;
int intFoo = 0;

//create recipient
Outlook.Recipient oRcp =
oNS.CreateRecipient("(e-mail address removed)");

//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
{
Outlook.Items oItms = (Outlook.Items)oFdr.Items;
oItms.IncludeRecurrences = true;

string strFilter = "([End] > \'September 1, 2006 12:00 AM\' AND
[Start] <= \'March 1, 2007 12:00 AM\')";

Outlook.Items oApps = oItms.Restrict(strFilter);
oApps.Sort("[Start]", false);
oApps.IncludeRecurrences = true; //blnIncludeRecurrences;

try
{
oAppt = (Outlook.AppointmentItem)oApps.GetFirst();
intFoo = (int)oAppt.Class;
}
catch
{
intFoo = 0;
}

if (intFoo == 26)
{
while (oAppt != null)
{
System.Windows.Forms.MessageBox.Show("Subject = " +
oAppt.Subject + " Start = " +
oAppt.Start.ToString("MMM dd, yyyy HH:mm"));

oAppt = (Outlook.AppointmentItem)oApps.GetNext();
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}




Tadwick said:
Hi Ken,

Thanks for the reply. My problem was defining the appointments in VBA as
Outlook.Appointment instead of object. That fixed the issue in VBA.
However, the problem that caused this is that I'm trying to convert my VBA
code to C# and I was getting mixed up with how appointment items are
defined
in the two languages. There is another article
(http://support.microsoft.com/?kbid=310265) that discusses C# and
recurrences
but I'm still getting the master appt for recurring appointments. This
only
happens to other users' folder, not my own. My code is below. Have you
tried this in dot net 2.0?

Thanks, Tad

public void GetAppointments(String recipient, String entryid)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");

//create recipient
Outlook.Recipient oRcp = oNS.CreateRecipient(recipient);

//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
{
Outlook.Items oItms = (Outlook.Items)oFdr.Items;

strFilter = "([End] > \'September 1, 2006 12:00 AM\' AND [Start] <=
\'March 1, 2007 12:00 AM\')";

Outlook.Items oApps = oItms.Restrict(strFilter);
oApps.Sort("[Start]",false);
oApps.IncludeRecurrences = true;//blnIncludeRecurrences;

Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oApps.GetFirst();

while (oAppt != null)
{
MessageBox.Show("Subject = " + oAppt.Subject + " Start = " +
oAppt.Start.ToString("MMM dd, yyyy HH:mm"));
oAppt = (Outlook.AppointmentItem)oApps.GetNext();
}
}
}
 
T

Tadwick

Hi Ken,

Thank you for trying to replicate the problem. I don't know think
permissions are a problem because I get the correct dates when I include
recurrences in VBA. I used your exact code to create a console app
(referencing OL2003 instead of 2007) and again I get the wrong dates.

Just to clarify, I get an instance of an appointment item for each occurence
but the start date is that of the master not the occurence. This is what was
happening in VBA when I was declaring items as oAppt to
Outlook.AppointmentItem instead of the correct type (object), which is why I
am wondering if it is related to the class definition in C#.

In your test, was the recurring item open ended or did it have an end date?

Thanks again for working with me on this one.

Tad

Ken Slovak - said:
Do you have sufficient permissions for accessing that mailbox and its
Calendar folder?

I did a quickie console app using C# and VS2005, Framework 2.0 running on
Outlook 2007.

I hard coded the mailbox recipient and since that Outlook setup has multiple
profiles I had to select an Exchange profile on startup. Other than that it
ran seamlessly and without errors and displayed one at a time all the
appointments.

I created 1 recurring appointment in my sales mailbox, but the principle
should apply even if the folder has many different appointments, mixing
recurring and non-recurring.

The Outlook profile used was my dog's profile against his mailbox on my
Exchange server, so Outlook was logged in as my dog. That profile was able
to access my sales mailbox, but my dog has permissions on that mailbox (he's
my sales manager).

Here's the code I used (appropriate references were set of course):

using System;
using System.Collections.Generic;
using System.Text;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Windows.Forms;

namespace ConsoleApplication1
{
public partial class Program
{
static void Main(string[] args)
{
bool Foobar = false;
Foobar = GetAppointments();
}

private static bool GetAppointments()
{

Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");
Outlook.AppointmentItem oAppt = null;
int intFoo = 0;

//create recipient
Outlook.Recipient oRcp =
oNS.CreateRecipient("(e-mail address removed)");

//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
{
Outlook.Items oItms = (Outlook.Items)oFdr.Items;
oItms.IncludeRecurrences = true;

string strFilter = "([End] > \'September 1, 2006 12:00 AM\' AND
[Start] <= \'March 1, 2007 12:00 AM\')";

Outlook.Items oApps = oItms.Restrict(strFilter);
oApps.Sort("[Start]", false);
oApps.IncludeRecurrences = true; //blnIncludeRecurrences;

try
{
oAppt = (Outlook.AppointmentItem)oApps.GetFirst();
intFoo = (int)oAppt.Class;
}
catch
{
intFoo = 0;
}

if (intFoo == 26)
{
while (oAppt != null)
{
System.Windows.Forms.MessageBox.Show("Subject = " +
oAppt.Subject + " Start = " +
oAppt.Start.ToString("MMM dd, yyyy HH:mm"));

oAppt = (Outlook.AppointmentItem)oApps.GetNext();
}
return true;
}
else
{
return false;
}
}
else
{
return false;
}
}
}
}




Tadwick said:
Hi Ken,

Thanks for the reply. My problem was defining the appointments in VBA as
Outlook.Appointment instead of object. That fixed the issue in VBA.
However, the problem that caused this is that I'm trying to convert my VBA
code to C# and I was getting mixed up with how appointment items are
defined
in the two languages. There is another article
(http://support.microsoft.com/?kbid=310265) that discusses C# and
recurrences
but I'm still getting the master appt for recurring appointments. This
only
happens to other users' folder, not my own. My code is below. Have you
tried this in dot net 2.0?

Thanks, Tad

public void GetAppointments(String recipient, String entryid)
{
Outlook.Application oApp = new Outlook.Application();
Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");

//create recipient
Outlook.Recipient oRcp = oNS.CreateRecipient(recipient);

//Get calendar info (appointments)
Outlook.MAPIFolder oFdr = oNS.GetSharedDefaultFolder(oRcp,
Outlook.OlDefaultFolders.olFolderCalendar);
if (oFdr != null)
{
Outlook.Items oItms = (Outlook.Items)oFdr.Items;

strFilter = "([End] > \'September 1, 2006 12:00 AM\' AND [Start] <=
\'March 1, 2007 12:00 AM\')";

Outlook.Items oApps = oItms.Restrict(strFilter);
oApps.Sort("[Start]",false);
oApps.IncludeRecurrences = true;//blnIncludeRecurrences;

Outlook.AppointmentItem oAppt =
(Outlook.AppointmentItem)oApps.GetFirst();

while (oAppt != null)
{
MessageBox.Show("Subject = " + oAppt.Subject + " Start = " +
oAppt.Start.ToString("MMM dd, yyyy HH:mm"));
oAppt = (Outlook.AppointmentItem)oApps.GetNext();
}
}
}
 
K

Ken Slovak - [MVP - Outlook]

My recurring appointment had an end date. About 20 occurrences were created.

There could be something with the Outlook 2003 PIA's I suppose. Do you have
any open ended recurring series?

I wonder if there'd be any difference running the code in VB.NET? I'll have
to see tomorrow. I can also fire up a VM with VS2005 and Outlook 2003 on it
tomorrow. I happened to be running a VM with Outlook 2007 on it when I was
writing the console app.

If you notice, I did cast the retrieved oAppt as an AppointmentItem.
 
T

Tadwick

Ken,

I can't believe this but I bumped up the permissions on a colleague's
mailbox from reviewer to editor and the actual dates showed up. How this can
be happening I don't know but I'm going to create a new post to this group
since the issue does seem to be permissions-related.

Simon
 

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