Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Testing if a user property exists

118 views
Skip to first unread message

Rémi

unread,
May 31, 2006, 4:00:02 AM5/31/06
to
Hello all,

Before performing a search on the calendar folder, I want to test if the
user property "test" exists in any of its items because if I don't test it,
an exception is raised.

Thank you

Rémi

Ken Slovak - [MVP - Outlook]

unread,
May 31, 2006, 8:59:38 AM5/31/06
to
You could test for IsEmpty on the property. What I usually do is just try
getting the value and if an error is thrown I add the user property. In .NET
code you'd wrap getting the property in a Try...Catch block. In VB 6 you'd
use On Error Resume Next and test the Err object.

--
Ken Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"Rémi" <R...@discussions.microsoft.com> wrote in message
news:0D7721DF-8B57-4222...@microsoft.com...

Sue Mosher [MVP-Outlook]

unread,
May 31, 2006, 10:53:13 AM5/31/06
to
Testing the items isn't going to tell you what you need to know. An property can be present on items in the folder, but not have a corresponding property definition at the folder level. And it's the definition at the folder level that is a prerequisite for searching.

If you're in any doubt about whether a property is present in the folder, perhaps the easiest course of action is simply to add the to the folder: Create a PostItem in the folder, use PostItem.UserProperties.Add to add the property, then discard the PostItem.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003
http://www.turtleflock.com/olconfig/index.htm
and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx



"Rémi" <R...@discussions.microsoft.com> wrote in message news:0D7721DF-8B57-4222...@microsoft.com...

Rémi

unread,
Jun 1, 2006, 4:07:01 AM6/1/06
to
If I understand well, there is no easy way to test if an user property
already exists in one of the appointmentitem of a calendar.
But the problem is that I don't understand why you are creating a PostItem
and then discard it ? Is it in order to avoid getting an exception when
trying to search on the user property ?

Sue Mosher [MVP-Outlook]

unread,
Jun 1, 2006, 7:29:24 AM6/1/06
to
> If I understand well, there is no easy way to test if an user property
> already exists in one of the appointmentitem of a calendar.

I don't think you understand yet at all. It is very easy to test whether a user property exists on an individual ***item*** -- just try to return it from the UserProperties collection. What is not easy to tell is whether the property is defined at the ***folder*** level, which is a prerequisite for being able to search on it programmatically.

> But the problem is that I don't understand why you are creating a PostItem
> and then discard it ? Is it in order to avoid getting an exception when
> trying to search on the user property ?

You discard it because you don't need it. The whole purpose of creating the item in the folder is to be able to set a custom property definition at the folder level, by adding the property to an item that you know exists in that folder.

Rémi

unread,
Jun 1, 2006, 9:06:03 AM6/1/06
to
Thanks.

I think I'll use the try/catch method. It seems me easier.

0 new messages