Outlook 2003 Addressbook Problem

I

I[c]E

Hi,

I'm developing a C# programm which should get the whole User Name from an A
lias by using MAPI and the Outlook (2003) Addressbook.
Here some Code:

//INIT
Microsoft.Office.Interop.Outlook.Application myOlapp=new
Microsoft.Office.Interop.Outlook.Application();
Microsoft.Office.Interop.Outlook.NameSpace
yNameSpace=myOlapp.GetNamespace("MAPI");
myNameSpace.Logon(null,null,false,false);
MAPI.Session session=new MAPI.SessionClass();
session.MAPIOBJECT=myOlapp.Session.MAPIOBJECT;
MAPI.AddressLists lists=(MAPI.AddressLists)session.AddressLists;
MAPI.AddressList list=(MAPI.AddressList)lists.get_Item("SV");
MAPI.AddressEntries entries=(MAPI.AddressEntries)list.AddressEntries;

//GET FILTER
MAPI.AddressEntryFilter filter=(MAPI.AddressEntryFilter)entries.Filter;
MAPI.Fields fields=(MAPI.Fields)filter.Fields;


foreach (string alias in AliasList)
{
//SET FILTER for alias
fields.Add(0x3A00001E/*ALIAS*/,alias,null,null);

//GET WANTED ENTRY
MAPI.AddressEntry entry=(MAPI.AddressEntry)entries.GetFirst();

if (entry!=null)
{
//GET USER NAME FIELD FROM ENTRY
MAPI.Fields fields2=(MAPI.Fields)entry.Fields;
MAPI.Field
field=(MAPI.Field)fields2.get_Item(0x3A00001E/*USERNAME*/,null);

if (field!=null)
{
string username=(string)field.Value;
.....
}
}
}


This Code works very well on my machine!
But on the machines of some collegues, 2 of 3 times the "entries.GetFirst()"
call causes the Exception "MAPI_E_INVALID_BOOKMARK", and no UserName can be
returned. Sometimes it works, sometimes not! It makes me crazy! Can anybody
please give me an idea for solving this problem?

Thx a lot!
IcE
 
Top