The opinions expressed herein are my own personal opinions. They are not necessarily fact or sactioned by any other person or organization. If you disagree that's your right. It's also my right to not care.
© Copyright 2009, Chris Tacke
So if you're working with Microsoft's new Microsoft.WindowsMobile.PocketOutlook namespace and trying to use the OutlookCollection.Restrict method to filter by a Contact's (or any PimItem's) ItemId field, you will likely run into a problem.
First, let me say the ItemID Class sucks. It exposes basically nothing useful but a ToString() method, even though it holds numeric data. And the first item added to POOM gets the ItemId of 0x80000001, which you might note is an *unsigned* number (again, the CLS is a pain for not allowing unsigned numbers). So if you have an ItemId class and you want to use it, you have to do something like this:
unchecked
Really, that's how you have to do it.
So, let's say we have a Contact's ItemId and we want to see if the current session has said Contact. One might try this:
m_outlookSession.Contacts.Items.Restrict("[ItemId]=" + itemId.ToString());
A nice try, but that gives you the not-so-helpful exception:
The query string is incorrectly formatted.Parameter name: [ItemId]=-2147483647
Alright, so ItemId only exposes itself as a string, and Restrict has little in the way of useful documentation or samples, so maybe we can try it as a string like so:
m_outlookSession.Contacts.Items.Restrict("[ItemId]='" + itemId.ToString() + “'“);
Well that gives a similar exception, just adding the single quotes:
The query string is incorrectly formatted.Parameter name: [ItemId]=-'2147483647'
Because I've used POOM from C++, I know that ItemId seems new to me, so just as a lark I figure I'll try 'Oid' as a field name instead, and keep it as a numeric:
m_outlookSession.Contacts.Items.Restrict("[Oid]=" + itemId.ToString());
Lo and behold, success!
Now technically this might not be a true bug, but it's sure not documented anywhere, nor would it be at all intuitive to guess if you'd not used C++ to access an IContact (which exports an Oid field, *not* an ItemId) before. Bad Windows Mobile Team. BAD!
Things needed:
Remember Me