Archive

Archive for the ‘VSTO’ Category

VSTO: Outlook – Add a contact programmatically – in C#

August 21st, 2009 No comments

Here goes the code:

            folder = this.Application.Session
.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts);
 
            Outlook.ContactItem ci = (ContactItem)folder
.Items.Add(OlItemType.olContactItem);
            ci.FirstName = "xyz";
            ci.LastName = "zyx";
            ci.Save();
VN:F [1.9.18_1163]
Rating: 0.0/5 (0 votes cast)
Categories: C#, Code Snippets, VSTO

How to add a button to Outlook Standard toolbar

July 23rd, 2009 No comments

Here goes a quick code. You need to write your own button removal code ;) This uses VSTO – for Office 2007

image

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
	Office.CommandBar cbar 
		= Application.ActiveExplorer().CommandBars["Standard"];
 
	Office.CommandBarButton btn 
		= (Office.CommandBarButton)cbar.Controls.Add(Office.MsoControlType.msoControlButton, 
		Type.Missing, Type.Missing, Type.Missing, true);
 
	btn.Click +=new Microsoft.Office.Core.
		_CommandBarButtonEvents_ClickEventHandler(btn_Click);
 
}
 
 
private void btn_Click(CommandBarButton Ctrl, 
			ref bool CancelDefault)
{
	MessageBox.Show("Clicked me!");
}
VN:F [1.9.18_1163]
Rating: 0.0/5 (0 votes cast)
Categories: C#, Code Snippets, VSTO