Null Contacts returned from MAPFolder.Items

L

leahann

I'm new to OL programming, am using C#, and am having an issue...

We have a Public Folder that contains a Contacts form with
approximately 5,000 contacts. We want to export this to an Excel
report programmatically.

Using Outlook.MAPIFolder.Folders[MY_FOLDER].Items.Count shows the
correct number of items, but when looping through these items after
about 2,000 they all end up being null. I've found a few topics on
this problem, but none seem to address the problem I'm having.

Is there a limit to the number of Items that can be returned from the
folder? Does anyone know a solution for this? ANY help would be
greatly appreciated!!!

My code:

Outlook.MAPIFolder aFolder =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders).Folders["My
Folder"]

Items items = aFolder.Items;

int itemCount = items.Count;
object item = items.GetFirst();

for(int i = 0; i < itemCount; i++)
{
ContactItem cItem = item as ContactItem;

if (cItem != null)
{
itemInfo[0] = cItem.LastName;
itemInfo[1] = cItem.FirstName;
itemInfo[2] = cItem.CompanyName;
...
}

allItems.Add(itemInfo);
itemInfo = new String[9];

item = items.GetNext();
}
 
K

Ken Slovak - [MVP - Outlook]

I'm not sure this is it, but I vaguely recall a problem with the Getxxx
constructs. See if using a direct assignment works: item = items
 
L

leahann

Yeah, I tried that already. It's actually the first way I tried to
access the items. When I kept receiving the null values, I thought
maybe the direct assignment was the problem, so I switched to looping
through with the GetNext() method.
 
K

Ken Slovak - [MVP - Outlook]

No idea then. It's not the famous 250 limit where you're limited to about
250 or so RPC channels, that would hit you much faster.
 
L

leahann

Hi Ken,

Thanks for you help. I think it actually was the 255 RPC channel
limit. Someone recommended invoking the GC, which seemed to do the
trick. I'm not sure why I was getting back several thousand items
before this limit hit its threshold, though. But, then again, GC seems
to be a bit fickle anyway, so it's not surprising.

Thanks!

Leah Ann
 
A

Alexa

Yes, I got the same problem when I was doing the same thing. I solved it by
sleeping the thread for every 5 contacts or so and then call the GC to clean
up the memory residue.

Alexa
 

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

Similar Threads


Top