Outlook 2003: How to move from Item array to GetNext()

J

John A. Bailo

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...
 
S

Sue Mosher [MVP-Outlook]

Nothing about the Items collection changed between versions. Did you install the PIAs for Office 2003?

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John A. Bailo

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
 
S

Sue Mosher [MVP-Outlook]

Go into your references and make sure you've removed any reference to Outlook or Office other than the PIAs you've just installed.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 
J

John A. Bailo

Sue said:
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.
 

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