The following Code sample guide you to get contact information form outlook ( 2003 or 2007). Before using this code, you need to refer “Microsoft outlook object libary “ in you project . 
Note 1: To execute this code outlook must be running in the machine. 
Note 2: You have to create an alias for a namespace “Microsoft.Office.Interop.Outlook” 
like using Outlook = Microsoft.Office.Interop.Outlook;
 private List GetContacts(string findLastName) 
        { 
            List foundContacts = new List(); 
            Outlook.Application outlookApp = new Outlook.ApplicationClass(); 
            Outlook.MAPIFolder folderContacts = outlookApp.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts); 
            Microsoft.Office.Interop.Outlook.Items searchFolder = folderContacts.Items; 
            foreach (Microsoft.Office.Interop.Outlook.ContactItem foundContact in searchFolder)
            { 
                if (foundContact.LastName.Contains(findLastName)) 
                { 
                    foundContact.Display(false); 
                    foundContacts.Add(foundContact);
                }
            } return foundContacts;
        }
No comments:
Post a Comment