Read Contacts Error

R

RBC

Hi,

I get following message in my code below:

Unable to cast COM object of type 'System.__ComObject' to interface type
'Microsoft.Office.Interop.Outlook.ContactItem'. This operation failed because
the QueryInterface call on the COM component for the interface with IID

What is missing in my code?

Thank you,
Rune

private void m_CONTACTS_method()
{
Int32 vm_COUNTER_ROW_Int32 = 0;

try
{
DataTable o_DataTable_Contact = new DataTable();
o_DataTable_Contact.Columns.Add( "FirstName" );
o_DataTable_Contact.Columns.Add( "LastName" );
o_DataTable_Contact.Columns.Add( "EmailAddress" );
o_DataTable_Contact.Columns.Add( "Phone" );
o_DataTable_Contact.Columns.Add( "Address" );

MAPIFolder o_MAPIFolder = null;
Application o_Application_Outlook = new
Application();
o_MAPIFolder = ( MAPIFolder
)o_Application_Outlook.Session.GetDefaultFolder(
OlDefaultFolders.olFolderContacts );

foreach ( ContactItem o_ContactItem in
o_MAPIFolder.Items )
{
{
vm_COUNTER_ROW_Int32++;

DataRow o_DataRow_NewRow =
o_DataTable_Contact.NewRow();
o_DataRow_NewRow["FirstName"] = (
o_ContactItem.FirstName == null ) ? string.Empty : o_ContactItem.FirstName;
o_DataRow_NewRow["LastName"] = (
o_ContactItem.LastName == null ) ? string.Empty : o_ContactItem.LastName;
o_DataRow_NewRow["EmailAddress"] =
o_ContactItem.Email1Address;
o_DataRow_NewRow["Phone"] =
o_ContactItem.Business2TelephoneNumber;
o_DataRow_NewRow["Address"] =
o_ContactItem.BusinessAddress;
o_DataTable_Contact.Rows.Add(
o_DataRow_NewRow );
}
}

}
catch ( System.Exception Exception_Error )
{
}
finally
{
}
}
 

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

Top