Click here to Skip to main content
15,887,676 members
Home / Discussions / C#
   

C#

 
GeneralRe: How to get outlook mails using add-ins Pin
Dave Kreskowiak9-Nov-12 1:49
mveDave Kreskowiak9-Nov-12 1:49 
QuestionConverting a stream of html to xml and reading the xml into a xmldocumet in c# Pin
Steve Holdorf7-Nov-12 23:05
Steve Holdorf7-Nov-12 23:05 
AnswerRe: Converting a stream of html to xml and reading the xml into a xmldocumet in c# Pin
Deflinek7-Nov-12 23:20
Deflinek7-Nov-12 23:20 
GeneralRe: Converting a stream of html to xml and reading the xml into a xmldocumet in c# Pin
Steve Holdorf8-Nov-12 2:40
Steve Holdorf8-Nov-12 2:40 
AnswerRe: Converting a stream of html to xml and reading the xml into a xmldocumet in c# Pin
Richard Deeming8-Nov-12 2:16
mveRichard Deeming8-Nov-12 2:16 
GeneralRe: Converting a stream of html to xml and reading the xml into a xmldocumet in c# Pin
Steve Holdorf10-Nov-12 1:07
Steve Holdorf10-Nov-12 1:07 
GeneralRe: Converting a stream of html to xml and reading the xml into a xmldocumet in c# Pin
Richard Deeming12-Nov-12 1:58
mveRichard Deeming12-Nov-12 1:58 
QuestionVSTO Outlook Visual C# - Create a ribbon that load a windows form integrated into outlook form? Pin
Cristian Capannini7-Nov-12 22:31
Cristian Capannini7-Nov-12 22:31 
Goodmorning to all!
Ehm i want create a button ribbon and when i press it load a windows form integrated into outlook 2010 or 2007 or 2013 (if it exited from building). Ehm i started creating button ribbon with this guide:

http://blogs.msdn.com/b/mcsuksoldev/archive/2010/07/12/building-and-deploying-an-outlook-2010-add-in-part-1-of-2.aspx

When i press it i would load a form into outlook that load all contacts of my public folder with this name "Contatti Itech" into a datagrid view.
How can i do it?
Plz help me! Big Grin | :-D
Thanks for any help! Code are appreciated too!!!

Ehm i forgot one thing:

C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Outlook = Microsoft.Office.Interop.Outlook;
using System.Reflection;
using System.Diagnostics;

namespace OutlookInteropSample
{
    public partial class MainForm : Form
    {
        private ToolTip contactToolTip = new ToolTip();
        private Outlook.MAPIFolder oContactsFolder = null;
      

        public MainForm()
        {
            InitializeComponent();
        }

        private void buttonGetContacts_Click(object sender, EventArgs e)
        {

            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");

            oContactsFolder = oNS.GetFolderFromID("000000001A447390AA6611CD9BC800AA002FC45A0300D4985F464F07654AA9CA8D6B785E166E000000004E3B0000", Type.Missing);
            Console.WriteLine(oContactsFolder.EntryID);
            
            
            getContacts(oContactsFolder);

            oApp = null;
            oNS = null;
          
        }

        private void ChiamaFunzia()
        {
           
        }

        private void listViewContacts_ItemMouseHover(object sender, ListViewItemMouseHoverEventArgs e)
        {
            contactToolTip.SetToolTip((Control)listViewContacts, getContactInfo((ListViewItem)e.Item));
            contactToolTip.Active = true;
        }

        private void getContacts(Outlook.MAPIFolder oContacts)
        {
            //Redemption.SafeContactItem rContact = new Redemption.SafeContactItem();
            try
            {
                listViewContacts.Items.Clear();
                string filter = "[MessageClass] = \"IPM.Contact\"";
                Outlook.Items oContactItems = oContacts.Items.Restrict(filter);
                foreach (Outlook.ContactItem oContact in oContactItems)
                {
                    try
                    {
                        //rContact = new Redemption.SafeContactItem();
                        //rContact.Item = oContact;

                        ListViewItem item = new ListViewItem();
                        item.Text = oContact.Email1DisplayName;
                        //item.Text = rContact.Email1DisplayName;
                        item.Tag = oContact;
                        this.listViewContacts.Items.Add(item);
                    }
                    catch (Exception ex)
                    {
                        Debug.WriteLine(ex.ToString());
                    }
                }
                oContactItems = null;
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.ToString(), this.Name);
            }
            finally
            {
                this.listViewContacts.EndUpdate();

                //rContact = null;
            }

            if (this.listViewContacts.Items.Count > 0)
            {
                this.buttonSendEmail.Enabled = true;
            }
            else
            {
                this.buttonSendEmail.Enabled = false;
            }
        }

        private string getContactInfo(ListViewItem contact)
        {
            //Redemption.SafeContactItem rContact = new Redemption.SafeContactItem();
            Outlook.ContactItem oContact = (Outlook.ContactItem)contact.Tag;
            //rContact.Item = oContact;

            StringBuilder sb = new StringBuilder();
            if (oContact.CompanyName != null && oContact.CompanyName.Length > 0) sb.AppendLine("Archivia come: " + oContact.CompanyName);
            //if (oContact.FileAs != null && oContact.FileAs.Length > 0) sb.AppendLine("Archivia come: " + oContact.FileAs);
            //if (oContact.LastName != null && oContact.LastName.Length > 0) sb.AppendLine("Last Name: " + oContact.LastName);
            //if (oContact.FirstName != null && oContact.FirstName.Length > 0) sb.AppendLine("First Name: " + oContact.FirstName);
            //if (oContact.MiddleName != null && oContact.MiddleName.Length > 0) sb.AppendLine("Middle Name: " + oContact.MiddleName);
            //if (oContact.Title != null && oContact.Title.Length > 0) sb.AppendLine("Title: " + oContact.Title);
            //if (oContact.JobTitle != null && oContact.JobTitle.Length > 0) sb.AppendLine("Job Title: " + oContact.JobTitle);

            //if (oContact.Email1Address != null && oContact.Email1Address.Length > 0) sb.AppendLine("Email Address: " + oContact.Email1Address);
            ////if (rContact.Email1Address != null && rContact.Email1Address.Length > 0) sb.AppendLine("Email Address: " + rContact.Email1Address);

            //if (oContact.WebPage != null && oContact.WebPage.Length > 0) sb.AppendLine("Web Page: " + oContact.WebPage);
            //if (oContact.BusinessTelephoneNumber != null && oContact.BusinessTelephoneNumber.Length > 0) sb.AppendLine("Business Telephone Number: " + oContact.BusinessTelephoneNumber);
            //if (oContact.OtherTelephoneNumber != null && oContact.OtherTelephoneNumber.Length > 0) sb.AppendLine("Telephone Number: " + oContact.OtherTelephoneNumber);
            //if (oContact.PagerNumber != null && oContact.PagerNumber.Length > 0) sb.AppendLine("Pager Number: " + oContact.PagerNumber);
            //if (oContact.MobileTelephoneNumber != null && oContact.MobileTelephoneNumber.Length > 0) sb.AppendLine("Cell Phone Number: " + oContact.MobileTelephoneNumber);

            //if (oContact.IMAddress != null && oContact.IMAddress.Length > 0) sb.AppendLine("IM Address: " + oContact.IMAddress);
            ////if (rContact.IMAddress != null && rContact.IMAddress.Length > 0) sb.AppendLine("IM Address: " + rContact.IMAddress);

            //if (oContact.BusinessFaxNumber != null && oContact.BusinessFaxNumber.Length > 0) sb.AppendLine("Business Fax Number: " + oContact.BusinessFaxNumber);

            //rContact = null;
            oContact = null;

            return sb.ToString();
        }

        private void listViewContacts_MouseLeave(object sender, EventArgs e)
        {
            contactToolTip.Active = false;
        }

        private void listViewContacts_DoubleClick(object sender, EventArgs e)
        {
            ListViewItem activeItem = ((ListView)sender).SelectedItems[0];
            if (activeItem != null)
            {
                Outlook.ContactItem oContact = (Outlook.ContactItem)activeItem.Tag;
                EditContact editBox = new EditContact(oContact);
                oContact = null;
                if (editBox.ShowDialog() == DialogResult.OK)
                {
                    getContacts(oContactsFolder);
                }
            }
        }

        private void buttonSendEmail_Click(object sender, EventArgs e)
        {
            Outlook.Application oApp = new Outlook.Application();

            if (this.listViewContacts.SelectedItems != null &&
                this.listViewContacts.SelectedItems.Count > 0)
            {
                Outlook.ContactItem oRecip = (Outlook.ContactItem)(this.listViewContacts.SelectedItems[0].Tag);
                //Redemption.SafeContactItem rRecip = new Redemption.SafeContactItem();
                //rRecip.Item = oRecip;

                Outlook.MailItem email = (Outlook.MailItem)(oApp.CreateItem(Outlook.OlItemType.olMailItem));
                //Redemption.SafeMailItem safeEmail = new Redemption.SafeMailItem();
                //safeEmail.Item = email;
                email.Recipients.Add(oRecip.Email1Address);
                //safeEmail.Recipients.Add(rRecip.Email1Address);
                email.Subject = "Just wanted to say...";
                email.Body = "Have a great day!";
                //safeEmail.Body = "Have a great day!";

                if (MessageBox.Show("Are you sure you want to send a good day message to " + oRecip.Email1DisplayName + "?", "Send?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                //if (MessageBox.Show("Are you sure you want to send a good day message to " + rRecip.Email1DisplayName + "?", "Send?", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    try
                    {
                        ((Outlook.MailItem)email).Send();
                        //((Redemption.SafeMailItem)safeEmail).Send();
                        MessageBox.Show("Email sent successfully.", "Sent");
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Email failed: " + ex.Message, "Failed Send");
                    }
                }

                oRecip = null;
                //rRecip = null;
                email = null;
                //safeEmail = null;
            }
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            Outlook.Application oApp = new Outlook.Application();
            Outlook.NameSpace oNS = oApp.GetNamespace("MAPI");

            oContactsFolder = oNS.PickFolder();
            getContacts(oContactsFolder);

            oApp = null;
            oNS = null;
        }
    }
}


The long string [000000001A447390AA6611CD9BC800AA002FC45A0300D4985F464F07654AA9CA8D6B785E166E000000004E3B0000] is id for my public folder. Is there anyway to get public folder by name such as "Contatti Itech"?
Thanks again!

modified 8-Nov-12 4:54am.

QuestionHow to convert string to Datetime including milliseconds Pin
Vijay Kanda7-Nov-12 21:45
Vijay Kanda7-Nov-12 21:45 
AnswerRe: How to convert string to Datetime including milliseconds Pin
Pete O'Hanlon7-Nov-12 22:18
mvePete O'Hanlon7-Nov-12 22:18 
AnswerRe: How to convert string to Datetime including milliseconds Pin
Braj_128-Nov-12 1:23
Braj_128-Nov-12 1:23 
GeneralRe: How to convert string to Datetime including milliseconds Pin
Vijay Kanda8-Nov-12 20:44
Vijay Kanda8-Nov-12 20:44 
GeneralRe: How to convert string to Datetime including milliseconds Pin
BobJanova8-Nov-12 23:24
BobJanova8-Nov-12 23:24 
GeneralRe: How to convert string to Datetime including milliseconds Pin
Vijay Kanda11-Nov-12 19:15
Vijay Kanda11-Nov-12 19:15 
GeneralRe: How to convert string to Datetime including milliseconds Pin
BobJanova11-Nov-12 22:10
BobJanova11-Nov-12 22:10 
Questionhow to sort Datalist using Dropdown which is not in the datalist control Pin
sreeCoderMan7-Nov-12 21:19
sreeCoderMan7-Nov-12 21:19 
Questiondatagridview child rows Pin
mynamearan7-Nov-12 20:18
mynamearan7-Nov-12 20:18 
AnswerRe: datagridview child rows Pin
Wayne Gaylard7-Nov-12 21:14
professionalWayne Gaylard7-Nov-12 21:14 
GeneralRe: datagridview child rows Pin
Mycroft Holmes7-Nov-12 22:08
professionalMycroft Holmes7-Nov-12 22:08 
GeneralRe: datagridview child rows Pin
Wayne Gaylard7-Nov-12 22:32
professionalWayne Gaylard7-Nov-12 22:32 
QuestionC# linq to sql default problem Pin
sc steinhayse7-Nov-12 12:57
sc steinhayse7-Nov-12 12:57 
AnswerRe: C# linq to sql default problem Pin
Mycroft Holmes7-Nov-12 13:12
professionalMycroft Holmes7-Nov-12 13:12 
GeneralRe: C# linq to sql default problem Pin
sc steinhayse7-Nov-12 18:14
sc steinhayse7-Nov-12 18:14 
GeneralRe: C# linq to sql default problem Pin
Mycroft Holmes7-Nov-12 18:26
professionalMycroft Holmes7-Nov-12 18:26 
AnswerRe: C# linq to sql default problem Pin
jschell8-Nov-12 8:49
jschell8-Nov-12 8:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.