Iterating Outlook Contacts

Hi there!, I have this very strange problem:

I want to iterate through Outlook contacts located in a public folder, but iteration stops randomly giving different error codes, among them these ones: -833601531, -695189499, -625983483, -37732347. Everytime I get the same text message: "The operation failed".

for (int i = 1; i <= mexicoContacts.Items.Count; i++)
{

if (mexicoContacts.ItemsIdea is Outlook.ContactItem)
{
Outlook.ContactItem contact = (Outlook.ContactItem)mexicoContacts.ItemsIdea;
if (contact.LastName != null)
listBox1.Items.Add(contact.LastName);
}


}

Any Ideas

Thanks...



Answer this question

Iterating Outlook Contacts

  • jameyer

    Finally!!!

    this is what I needed:

    using System.Runtime.InteropServices;

    ...

    Marshal.ReleaseComObject(contact); // after using each object


  • _mthz

    Some good news:

    I added a try / catch block and now I always logoff from Outlook namespace... error shows me this:

    Microsoft Office Outlook
    A first chance exception of type 'System.Runtime.InteropServices.COMException' occurred in Phone Usage Reporter.exe at Outlook.ItemsClass.get_Item(Object Index)
    at Phone_Usage_Reporter.formMain.linkUpdate_LinkClicked(Object sender, LinkLabelLinkClickedEventArgs e) in C:\Documents and Settings\itsadmin\My Documents\Visual Studio 2005\Projects\Toolbox\Phone Usage Reporter\Phone Usage Reporter\Form1.cs:line 39

    Any Ideas


  • minority80

    Hi again, after some hours I found this in Event Viewer:

    Source: MSExchangeIS
    EventID: 9646
    Mapi session "/o=MX/ou=first administrative group/cn=Recipients/cn=user" exceeded the maximum of 250 objects of type "objtMessage".

    Following the related link found this:

    http://support.microsoft.com/default.aspx scid=kb;en-us;830836&sd=ee

    So, this is not a C# problem but an Exchange problem... and it's hard for me to get the server registry changed as proposed in the previous link... any ideas on this how does outlook get more than 250 items without problems

    This is driving me crazy guys...


  • Vista2007new

    I have something else: I can read item 166 but can't read item 165... strange... that makes me think it's something related to the way the item was saved...


  • Iterating Outlook Contacts