A Microsoft Outlook email forum. Outlook Banter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Add-ins for Outlook
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Null Contacts returned from MAPFolder.Items



 
 
Thread Tools Search this Thread Display Modes
  #1  
Old May 11th 06, 10:00 PM posted to microsoft.public.outlook.program_addins
[email protected]
external usenet poster
 
Posts: 5
Default Null Contacts returned from MAPFolder.Items

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.OlDefaultFo lders.olPublicFoldersAllP*ublicFolders).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();
}



Thanks!

leahann

Ads
  #2  
Old May 12th 06, 07:17 PM posted to microsoft.public.outlook.program_addins
Dmitry Streblechenko
external usenet poster
 
Posts: 2,116
Default Null Contacts returned from MAPFolder.Items

1. If you are using a for (1..Count) loop there is no reason to use
GetFirst/GetNext
for(int i = 1; i = itemCount; i++)
{
item = items[i];
ContactItem cItem = item as ContactItem;

2. If you prefer to use GetFirst/GetNext, use a while loop.

3. Try to invoke GC.Collect() at each step of the loop (you can also try 50
or so steps instead) - Exchange has a limit of 255 RPC channels open at any
given time, so you can easily run over teh limit, especially with .Net,
which does not immediately release the COM objects.

4. Keep in mind that you can have distributions lists as well as contacts.
Your code will fail if you hit a DistListItem object instead of ContactItem.


Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

wrote in message
ups.com...
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.OlDefaultFo lders.olPublicFoldersAllP*ublicFolders).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();
}



Thanks!

leahann


  #3  
Old May 12th 06, 08:40 PM posted to microsoft.public.outlook.program_addins
[email protected]
external usenet poster
 
Posts: 5
Default Null Contacts returned from MAPFolder.Items

Well, isn't it always the simple thing that ends up being the solution?
I invoked the GC and it looks as though everything is coming back now.
(Oh, and the for loop was a lazy leftover from several attempts at
accessing the items in different ways, namely a direct assign.) Thanks
for your help!

leahann

 




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Null Contacts returned from MAPFolder.Items [email protected] Outlook - Using Contacts 5 May 15th 06 04:21 PM
30 of 89 mailings are returned too many recipients? Why? lexluther Outlook - Using Contacts 1 April 4th 06 09:33 AM
Please help with returned emails from new domain JM Outlook - General Queries 7 March 14th 06 04:06 PM
Error report on returned mail. Buiskop19 Outlook Express 13 February 24th 06 01:26 PM
Blank form returned brianlowry Outlook - Using Forms 1 January 11th 06 07:41 AM


All times are GMT +1. The time now is 09:22 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.