Hi all I'm using trying to get my app to read in all contacts in the contact folder of Outlook. I'm using the Outlook Security manager to stop the pop up warnings. Outlook version is 2002(10.2627.2625) I can create a contact in Outlook and I can use it to send an email. It's just the getting the contacts list that doesn't work. The thing is it also works on my dev machine but not on the users machine.
The code I'm using:
SecurityManager = new AddinExpress.Outlook.SecurityManager();
try
{
Outlook._Application outlookObj = new Outlook.Application();
Outlook.MAPIFolder fldContacts =
(Outlook.MAPIFolder)outlookObj.Session.GetDefaultF older(Outlook.OlDefaultFolders.olFolderContacts);
Outlook.Items searchFolder = fldContacts.Items;
Outlook.ContactItem contactItem = (Outlook.ContactItem)searchFolder.GetFirst();
//Code to create a data table to put the contact info into.
SecurityManager.ConnectTo(outlookObj);
SecurityManager.DisableOOMWarnings = true;
while (contactItem != null)
{
dr = dt.NewRow();
dr[0] = contactItem.FirstName;
dr[1] = contactItem.LastName;
//etc etc etc
dt.Rows.Add(dr);
contactItem = (Outlook.ContactItem)searchFolder.GetNext();
}
dv = new DataView(dt);
dv.Sort = "First Name ASC";
dgContacts.DataSource = dv;
}
catch (Exception ex)
{
Console.WriteLine(ex);
MessageBox.Show("Contact List could not be retrieved from Outlook", "Contacts not retrieved",
MessageBoxButtons.OK, MessageBoxIcon.Error);
this.Close();
}
finally
{
SecurityManager.DisableOOMWarnings = false;
}
Can anyone see anything wrong here? I for the life of me can't figure out what is going on. I thought that the problem was with different versions of Outlook, but they are the same. Oh and I'm not using the enumeration for the Contacts Folder because Outlook 2002 doesn't support it. If I tried to use this code on Outlook 2003 would it work?