Calender folder returns no appointments


M

Mk23

Hi

I have a problem by getting the appointment from an calendar folder. I use
the PIA from Office XP and have a Outlook 2007. At the most customer it works
fine, but at a few PC's it doesn't work. That mean, i get no appointment
items, althought the user has a lot of them in his calendar.

I get the items by the following sample code:

//Select folder
Microsoft.Office.Interop.Outlook.Application app = new
Microsoft.Office.Interop.Outlook.Application();
NameSpace olNameSpace = app.Session;
olFolder = olNameSpace.PickFolder();

//Create filter string
CultureInfo userCulture = new CultureInfo(GetUserDefaultLCID());
string restrictExpression = string.Format("[Start]>='{0}' AND
[Start]<'{1}'",
_dateFrom.Value.ToString("g", userCulture.DateTimeFormat),
_dateTill.Value.ToString("g", userCulture.DateTimeFormat));

//Get filtered items and sort them
Items folderItems = olFolder.Items;
Items restrictedItems = folderItems.Restrict(restrictExpression);
restrictedItems.Sort("[Start]", Missing.Value);

//Loop all appointment elements
object itemObject = restrictedItems.GetFirst();
while (itemObject != null)
{
...
}

Does anyone have an hint for me

Regards
Thomas
 
Ad

Advertisements

K

Ken Slovak - [MVP - Outlook]

Is this an outside program or a COM addin?

In either case I'd recommend setting NameSpace by using GetNameSpace("MAPI")
and not just by referencing Session. Although I don't think that has
anything to do with your problem.

Does the code run all the way through with no exceptions? Have you been able
to step the code in debug mode and see what's happening? What about
diagnostic logging, are you doing any so you can check at various
checkpoints to see what values are there for key objects such as your filter
string, the default item type for the folder selected from PickFolder(), the
raw count of both the filtered and unfiltered Items collections, etc?
 
M

Mk23

Hi Ken

- The main application is a COM addin. But i wrote a smal sample project
with just the necessary code to get the calendar item. This sample is an
outside program. I can reproduce the error with both.
- The code run through with no exception.
- I ckeck the item type for the folder, so that it has to be a calendar.
- I can't reproduce the exception at an own system, only at the customer.
There I'am not able to debug.
- I have made a few logging to see the state of some object's.

That for the moment. I will post a few more info's when i have all
information you asked for.
 
M

Mk23

Hi Ken

Here I have a few more Informations from the customer log:
DefaultItemType: olAppointmentItem
restriction expression: [Start]>='18.02.2009 00:00' AND
[Start]<'18.05.2009 00:00'
UnfilteredItems: 404
FilteredItems: 0

So it seems to be a problem with the restriction expression. How has this
string to be formated, that it work?

I checked this string at my own system, there I have the same string and it
work's fine. My personal log:
restriction expression: [Start]>='18.02.2009 00:00' AND [Start]<'18.05.2009
00:00'
UnfilteredItems: 405
FilteredItems: 124

Regards Thomas
 
K

Ken Slovak - [MVP - Outlook]

The VBA Object Browser Help on Restrict says you should format the date
string so it's formatted as Outlook expects. The example there is this,
using LastModificationTime as the field in the filter:

sFilter = "[LastModificationTime] > '" & Format("1/15/99 3:30pm", "ddddd
h:nn AMPM") & "'"
 
M

Mk23

Yes this hint i have seen also.
But this can't be true, because inside the 'AMPM' part of this format string
the 'M' character will be replaced with the Minute part of the formated Date
(tested in C#)!
 
Ad

Advertisements

K

Ken Slovak - [MVP - Outlook]

C# is not VBA. You must use the equivalent formatting that is appropriate
for C#. Run the line used in the example in Outlook VBA code and see that it
doesn't use the M of AMPM in the way you describe.
 
M

Mk23

Hi Ken

Naturally you have right with the replacement, sorry.

But on the other side it doesn't help anything if I format the string the
way you/the help discribe. It is still the same, it doesn't work.

The formated string was:
[Start]>='2/19/2009 12:00 AM' AND [Start]<'5/19/2009 12:00 AM'

Regards Thomas
 
K

Ken Slovak - [MVP - Outlook]

All I can suggest is to use Debug.WriteLine() to show the filter you end up
with in C# and then use the original VBA code and see what that filter looks
like. Make sure they look the same. Also make sure that the VBA code works
as expected when you run it using that filter.
 
Ad

Advertisements

M

Mk23

At the end we placed a call to microsoft.
We tried a lot of things, but didn't find the reason, for this strange
behaviour. In the end we deleted the profile of the user and it worked again.
 

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

Similar Threads


Top