After upgrading from Outlook 2000 to the 2003 object model, some of my
Outlook automation code no longer functions.
For example, in 2000, I used to be able to loop through a list of .Items
in a folder and refer to each as .Item(n)
Say for example, my folder contained MailItem and PostItem -- I could
treat each differently by casting .Item(n) differently.
if(myFolder.Items.Item(2) is Outlook.PostItem)
Outlook.PostItem myPI =
(Outlook.PostItem) myFolder.Items.Item(2);
But, now there is no more Item -- there is .GetNext()
However, what generic object type can I cast the return object of
.GetNext() to before using .GetType() to see what object type it is?
Or do I have to do, .GetNext() and then a .GetPrevious() ?
Example:
if(myFolder.Items.GetNext().GetType() is PostItem)
Outlook.PostItem myPI =
(Outlook.PostItem) myFolder.Items.GetPrevious();
...seems like wasteful enumeration, iteration...
Sue Mosher [MVP-Outlook] - 04 May 2006 23:47 GMT
Nothing about the Items collection changed between versions. Did you install the PIAs for Office 2003?

Signature
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
>
> After upgrading from Outlook 2000 to the 2003 object model, some of my
[quoted text clipped - 24 lines]
>
> ...seems like wasteful enumeration, iteration...
John A. Bailo - 05 May 2006 00:38 GMT
I just installed them and added the reference to my project.
On compile:
This line:
if (objFolders.Item(i).Name == "Public Folders")
GeneralFolders = objFolders.Item(i);
Gives this error:
C:\Documents and Settings\jbailo\My Documents\pc298 Documents\Visual
Studio Projects\OutlookEmail\Email.cs(158):
'Microsoft.Office.Interop.Outlook.Folders' does not contain a definition
for 'Item'
Same exact error as before.
This code compiled under Outlook 2000
> Nothing about the Items collection changed between versions. Did you install the PIAs for Office 2003?
Sue Mosher [MVP-Outlook] - 05 May 2006 01:06 GMT
Go into your references and make sure you've removed any reference to Outlook or Office other than the PIAs you've just installed.

Signature
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
>
> I just installed them and added the reference to my project.
[quoted text clipped - 18 lines]
>
>> Nothing about the Items collection changed between versions. Did you install the PIAs for Office 2003?
John A. Bailo - 05 May 2006 17:36 GMT
> Go into your references and make sure you've removed any reference to Outlook or Office other than the PIAs you've just installed.
I did remove it.
I also found that there was a bug with the .GetNext() method for items
in folders. I could do a .GetFirst() and then a .GetNext() but all
subsequent .GetNext()'s in a loop would not run.
In my research, I found that there are bug reports (including at MS)
going all the way back to the Outlook 97 OM !
Anyway, I solved my problem by going with a foreach(System.Object _item
in myFolders) instead.