I need to develop an Outlook 2010 add-in, and I'm new to Visual Studio and C #, since I mostly use PHP and JavaScript. I am using Visual Studio 2010, and I created a project using the built-in Outlook 2010 add-in template. Consider the following code:
// file ThisAddIn.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Forms; using System.Xml.Linq; using Outlook = Microsoft.Office.Interop.Outlook; using Office = Microsoft.Office.Core; namespace OutlookAddIn1 { public partial class ThisAddIn { private void ThisAddIn_Startup(object sender, System.EventArgs e) { } private void ThisAddIn_Shutdown(object sender, System.EventArgs e) { } public string displayCount() { Outlook.MAPIFolder inbox = this.Application.ActiveExplorer().Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox); Outlook.Items unreadItems = inbox.Items.Restrict("[Unread]=true"); return string.Format("Unread items in Inbox = {0}", unreadItems.Count); } #region VSTO generated code /// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InternalStartup() { this.Startup += new System.EventHandler(ThisAddIn_Startup); this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown); } #endregion } } // file Ribbon1.cs using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Office.Tools.Ribbon; namespace OutlookAddIn1 { public partial class Ribbon1 { private void Ribbon1_Load(object sender, RibbonUIEventArgs e) { } private void button1_Click(object sender, RibbonControlEventArgs e) { // call ThisAddIn.displayCount() here } } }
The question is, how can I call public methods from the ThisAddIn class of the Ribbon1 class, or somewhere else? I know that I need an object reference, but how do I know the instance name? I do not see an instance of ThisAddIn that is being created somewhere in existing files. Or am I misunderstanding the concept, and it has to be done in other ways? I would appreciate any advice or links to information on creating Office add-ins.
source share