locked
Several contactItems to public folder RRS feed

  • Question

  • Hello,

    I'm having some difficulties with adding several contacts into a public folder.

    In my Outlook addin i create 300 ContactItems and I loop through all of them like this:

                foreach (Outlook.ContactItem contact in contactList)
                {
                    Outlook.ContactItem c = destFolder.Items.Add(Outlook.OlItemType.olContactItem) as Outlook.ContactItem;
                    
                    try
                    {
                        c.FullName = contact.FullName;
                        c.Email1Address = contact.Email1Address;
                        c.CustomerID = contact.CustomerID;
                        c.Save();                   
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                }

    The strange problem appear when i get to contact number 250, then it suddenly throws an exception:

        {"The operation failed."}
            [System.Runtime.InteropServices.COMException]: {"The operation failed."}
            Data: {System.Collections.ListDictionaryInternal}
            HelpLink: null
            InnerException: null
            Message: "The operation failed."
            Source: "Microsoft Office Outlook"
            StackTrace: "   at Microsoft.Office.Interop.Outlook._ContactItem.Save()\r\n   at ExchangePerformance.ThisAddIn.InsertContacts(List`1                 contactList) in C:\\Projects\\OutlookIntegration\\ExchangePerformance\\ExchangePerformance\\ThisAddIn.cs:line 103"
            TargetSite: {Void Save()}

    I can see that 250 contacts have been inserted to the public folder, and if i try any local contacts folder there are no problems.

    Does anyone have an idea why I can not insert all 300 contacts this way?
    Thursday, January 18, 2007 11:25 AM

Answers

  • Outlook has a limit of 255 open RPC channels to the Exchange server. One solution is to release objects and invoke the garbage collector more aggressively. Another one that might work is to set Outlook to cache folders in Public Folders\Favorites and then add your target folder there. THat way, you'd be making your additions in the local cache and letting Outlook handle synching the data up to the server in the background.
    Thursday, January 18, 2007 1:34 PM