private void buttonStartExample_Click(object sender, EventArgs e) { // start outlook by trying to access running application first Outlook.Application outlookApplication = COMObject.CreateByRunningInstance <Outlook.Application>(); // enum contacts int i = 0; Outlook.MAPIFolder contactFolder = outlookApplication.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts); foreach (ICOMObject item in contactFolder.Items) { Outlook.ContactItem contact = item as Outlook.ContactItem; if (null != contact) { i++; ListViewItem listItem = listViewContacts.Items.Add(i.ToString()); listItem.SubItems.Add(contact.CompanyAndFullName); } } // close outlook and dispose if (!outlookApplication.FromProxyService) { outlookApplication.Quit(); } outlookApplication.Dispose(); }
private void btnStart_Click(object sender, EventArgs e) { if (m_app == null) { m_app = new Outlook.Application(); Outlook._NameSpace ns = m_app.GetNamespace("MAPI"); foreach (Outlook.MAPIFolder folder in ns.Folders) { txtResults.AppendText(string.Format("{0} - {1}\r\n", folder.Name, folder.DefaultItemType)); TraverseFolders(folder); } Outlook.MAPIFolder selectedFolder = ns.GetFolderFromID("00000000C5B7DEF515463948B280312D7005404A02870000"); foreach (object oItem in selectedFolder.Items) { if (oItem is Outlook.ContactItem) { Outlook.ContactItem item = (Outlook.ContactItem)oItem; txtResults.AppendText(string.Format("{0}/{1}\r\n", item.FirstName, item.LastName)); if (string.Equals("LastName", item.LastName)) { propertyGrid1.SelectedObject = item; var props = TypeDescriptor.GetProperties(item); foreach (PropertyDescriptor prop in props) { try { txtResults.AppendText(string.Format("{0} : {1}\r\n", prop.DisplayName, prop.GetValue(item))); } catch (Exception ex) { Console.WriteLine(ex.Message); } } } } } } }
public TestResult DoTest() { Outlook.Application application = null; DateTime startTime = DateTime.Now; try { // start outlook application = COMObject.CreateByRunningInstance <Outlook.Application>(COMObjectCreateOptions.CreateNewCore); NetOffice.OutlookSecurity.Suppress.Enabled = true; // enum contacts Outlook.MAPIFolder contactFolder = application.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts); for (int i = 1; i <= contactFolder.Items.Count; i++) { Outlook.ContactItem contact = contactFolder.Items[i] as Outlook.ContactItem; if (null != contact) { Console.WriteLine(contact.CompanyAndFullName); } } return(new TestResult(true, DateTime.Now.Subtract(startTime), "", null, string.Format("{0} ContactFolder Items.", contactFolder.Items.Count))); } catch (Exception exception) { return(new TestResult(false, DateTime.Now.Subtract(startTime), exception.Message, exception, "")); } finally { if (null != application) { if (!application.FromProxyService) { application.Quit(); } application.Dispose(); } } }
private void buttonStartExample_Click(object sender, EventArgs e) { // start outlook Outlook.Application outlookApplication = new Outlook.Application(); // enum contacts int i = 0; Outlook.MAPIFolder contactFolder = outlookApplication.Session.GetDefaultFolder(OlDefaultFolders.olFolderContacts); foreach (COMObject item in contactFolder.Items) { Outlook.ContactItem contact = item as Outlook.ContactItem; if (null != contact) { i++; ListViewItem listItem = listViewContacts.Items.Add(i.ToString()); listItem.SubItems.Add(contact.CompanyAndFullName); } } // close outlook and dispose outlookApplication.Quit(); outlookApplication.Dispose(); }