Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:28:13+00:00 2026-05-25T23:28:13+00:00

I need to develop an Outlook 2010 add-in and I am new to Visual

  • 0

I need to develop an Outlook 2010 add-in and I am new to Visual Studio and C#, as I mostly use PHP and JavaScript. I am using Visual Studio 2010 and I’ve created a project using built-in Outlook 2010 add-in template. Consider the folowing 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 do I call public methods from ThisAddIn class in Ribbon1 class or anywhere else? I know that I need an object reference, but how can I find out the name of an instance? I can’t see an instance of ThisAddIn being created anywhere in existing files. Or do I misunderstand the concept and it should be done in other ways? I would appreciate any advice or links to information on creating Office add-ins too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:28:14+00:00Added an answer on May 25, 2026 at 11:28 pm

    I use a static member variable (with an associated static getter) that is set upon initialization of the add-in: then I can access it as Core (choose name as appropriate) from anywhere in the code-base. Of course, I try to pass around the add-in object if it is available in context, but sometimes it’s hard to do.

    The class is instantiated automatically by the add-in container/loader (it is really exposed as a COM component, at least this is how it works in ADX :).

    Happy coding.


    The code might look something like this:

    // inside ThisAddIn class
    public static ThisAddIn Active {
      get;
      private set;
    }
    
    // inside ThisAddIn_Startup
    Active = this;
    
    // later on, after add-in initialization, say in Ribbon1.button1_Click
    ThisAddIn.Active.displayCount();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to develop an Outlook add-on. I must support Office 2003 and office
I need to develop a easy web site, I usually use bootstrap CSS framework,
I need to develop an HTML5 mobile business application using PhoneGap. After finishing my
I need to develop a drag-able and editable tree view. Any javascript components to
I need to develop a Desktop application for mac and Windows, Using HTML JqueryMobile
I need to develop image zoom-in functionality with JavaScript and HTML5. Which strategy will
I need to develop an application that connects to various DSN's using the Microsoft
I need to develop an application, which adds telephone numbers to existing or new
I need to develop an app that is using multithreading. Basicly, I have a
I need to develop a javascript based diagrammer for designing node-and-connector diagrams for things

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.