none
Custom Tab and a custom Links in Outlook 2010 RRS feed

  • Question

  • Hello,

    How can I created an add in to add a new tab and add a link page or a list of links?

    Any help will be appreciated.

    Thank you,

    Rad


    Radshaykho

    Monday, April 30, 2012 3:56 AM

Answers

  • Hi Rad11,

    OK, let's know where you will display the hyperlink? I Show you a sample that will display the hyperlink in IE.

    Ribbon1.cs

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using Office = Microsoft.Office.Core;
    using System.Diagnostics;
    
    // TODO:  Follow these steps to enable the Ribbon (XML) item:
    
    // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
    
    //  protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    //  {
    //      return new Ribbon1();
    //  }
    
    // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
    //    actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
    //    move your code from the event handlers to the callback methods and modify the code to work with the
    //    Ribbon extensibility (RibbonX) programming model.
    
    // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.  
    
    // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
    
    
    namespace OutlookAddIn8
    {
        [ComVisible(true)]
        public class Ribbon1 : Office.IRibbonExtensibility
        {
            private Office.IRibbonUI ribbon;
            private Dictionary<string, string> LinkMap = null;
    
            public Ribbon1()
            {
                LinkMap = new Dictionary<string, string>();
                LinkMap.Add("MSDN", "http://msdn.microsoft.com/en-US");
                LinkMap.Add("MSDN Forum", "http://social.msdn.microsoft.com/Forums/en-US/categories");
                LinkMap.Add("Office Development Forum",
                    "http://social.msdn.microsoft.com/Forums/en-US/category/officedev");
                LinkMap.Add("Outlook Development Forum",
                    "http://social.msdn.microsoft.com/Forums/en-US/outlookdev/threads");
                LinkMap.Add("Outlook Answer Forum",
                    "http://answers.microsoft.com/en-us/office/forum/outlook");
            }
    
            #region IRibbonExtensibility Members
    
            public string GetCustomUI(string ribbonID)
            {
                string result = string.Empty;
                switch (ribbonID)
                {
                    case "Microsoft.Outlook.Explorer":
                        result = GetResourceText("OutlookAddIn8.Ribbon1.xml");
                        break;
                }
                //return GetResourceText("OutlookAddIn8.Ribbon1.xml");
                return result;
            }
    
            #endregion
    
            #region Ribbon Callbacks
            //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
    
            #endregion
    
            #region Helpers
    
            private static string GetResourceText(string resourceName)
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string[] resourceNames = asm.GetManifestResourceNames();
                for (int i = 0; i < resourceNames.Length; ++i)
                {
                    if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                        {
                            if (resourceReader != null)
                            {
                                return resourceReader.ReadToEnd();
                            }
                        }
                    }
                }
                return null;
            }
    
            #endregion
    
            public int GetLinksCount(Office.IRibbonControl Control)
            {
                return LinkMap.Count;
            }
    
            public string GetLinksLabel(Office.IRibbonControl Control, int Index)
            {
                List<string> keys = LinkMap.Keys.ToList<string>();
                return keys[Index];
            }
    
            public void LinkSelected(Office.IRibbonControl Control,string SelectId,
                int SelectIndex)
            {
                List<string> values = LinkMap.Values.ToList<string>();
                Process.Start("IExplore.exe", values[SelectIndex]);
            }
        }
    }

    Ribbon1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab id="MyTab" label="MyTab">
            <group id="MyFavoriteLinks"
                   label="My Favorite Links">
              <dropDown id="FavoriteLinksDropDown" getItemCount ="GetLinksCount"
                        getItemLabel="GetLinksLabel" onAction="LinkSelected"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by 许阳(无锡)Moderator Monday, May 7, 2012 7:31 AM
    • Unmarked as answer by Rad1 Tuesday, May 8, 2012 1:22 AM
    • Marked as answer by Rad1 Tuesday, May 8, 2012 1:22 AM
    Wednesday, May 2, 2012 5:21 AM
    Moderator

All replies

  • Hello,

    How can I create an add in to add a new tab and add a link page or a list of links?

    Any help will be appreciated.

    Thank you,

    Rad


    Radshaykho

    Monday, April 30, 2012 3:59 AM
  • http://msdn.microsoft.com/en-us/library/aa338202(v=office.12).aspx for ribbon customization.

    What do you mean by 'link page'? You can add links programmatically without problems, but i;m not sure what do you mwan by page.

    Monday, April 30, 2012 7:58 AM
  • Thank you!

    I mean creating a tab and a command control which holds a list of links such as MSN.com, Yahoo.com, Google.com, etc.

    Thank you,

    Rad

    Monday, April 30, 2012 7:33 PM
  • Hi Rad1,

    Thanks for posting in the MSDN Forum.

    I think you need clarify it.

    add a new tab and add a link page or a list of links
    1. Where is the tab in?
    2. What's mean of "link page"?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 1, 2012 6:10 AM
    Moderator
  • Hi Rad11,

    Thanks for posting in the MSDN Forum.

    Where do you display the Webset? In Outlook's explorer or IE? Or you just want to embedded the hyperlink to a mail item's body?

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, May 1, 2012 6:15 AM
    Moderator
  • Hi Tom,

    The Tab need to be on the Ribbon, and the command control need to be a list of links and in the new Tab.

    It will also be very nice if the users can drag and drop links to the command control which will display the links (just like Favorite).

    Please let me know if you want more information.

    Thank you,

    Rad11


    • Edited by Rad11 Tuesday, May 1, 2012 8:27 PM
    Tuesday, May 1, 2012 8:26 PM
  • Hi Rad11,

    OK, let's know where you will display the hyperlink? I Show you a sample that will display the hyperlink in IE.

    Ribbon1.cs

    using System;
    using System.Collections.Generic;
    using System.IO;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using System.Text;
    using Office = Microsoft.Office.Core;
    using System.Diagnostics;
    
    // TODO:  Follow these steps to enable the Ribbon (XML) item:
    
    // 1: Copy the following code block into the ThisAddin, ThisWorkbook, or ThisDocument class.
    
    //  protected override Microsoft.Office.Core.IRibbonExtensibility CreateRibbonExtensibilityObject()
    //  {
    //      return new Ribbon1();
    //  }
    
    // 2. Create callback methods in the "Ribbon Callbacks" region of this class to handle user
    //    actions, such as clicking a button. Note: if you have exported this Ribbon from the Ribbon designer,
    //    move your code from the event handlers to the callback methods and modify the code to work with the
    //    Ribbon extensibility (RibbonX) programming model.
    
    // 3. Assign attributes to the control tags in the Ribbon XML file to identify the appropriate callback methods in your code.  
    
    // For more information, see the Ribbon XML documentation in the Visual Studio Tools for Office Help.
    
    
    namespace OutlookAddIn8
    {
        [ComVisible(true)]
        public class Ribbon1 : Office.IRibbonExtensibility
        {
            private Office.IRibbonUI ribbon;
            private Dictionary<string, string> LinkMap = null;
    
            public Ribbon1()
            {
                LinkMap = new Dictionary<string, string>();
                LinkMap.Add("MSDN", "http://msdn.microsoft.com/en-US");
                LinkMap.Add("MSDN Forum", "http://social.msdn.microsoft.com/Forums/en-US/categories");
                LinkMap.Add("Office Development Forum",
                    "http://social.msdn.microsoft.com/Forums/en-US/category/officedev");
                LinkMap.Add("Outlook Development Forum",
                    "http://social.msdn.microsoft.com/Forums/en-US/outlookdev/threads");
                LinkMap.Add("Outlook Answer Forum",
                    "http://answers.microsoft.com/en-us/office/forum/outlook");
            }
    
            #region IRibbonExtensibility Members
    
            public string GetCustomUI(string ribbonID)
            {
                string result = string.Empty;
                switch (ribbonID)
                {
                    case "Microsoft.Outlook.Explorer":
                        result = GetResourceText("OutlookAddIn8.Ribbon1.xml");
                        break;
                }
                //return GetResourceText("OutlookAddIn8.Ribbon1.xml");
                return result;
            }
    
            #endregion
    
            #region Ribbon Callbacks
            //Create callback methods here. For more information about adding callback methods, select the Ribbon XML item in Solution Explorer and then press F1
    
            public void Ribbon_Load(Office.IRibbonUI ribbonUI)
            {
                this.ribbon = ribbonUI;
            }
    
            #endregion
    
            #region Helpers
    
            private static string GetResourceText(string resourceName)
            {
                Assembly asm = Assembly.GetExecutingAssembly();
                string[] resourceNames = asm.GetManifestResourceNames();
                for (int i = 0; i < resourceNames.Length; ++i)
                {
                    if (string.Compare(resourceName, resourceNames[i], StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        using (StreamReader resourceReader = new StreamReader(asm.GetManifestResourceStream(resourceNames[i])))
                        {
                            if (resourceReader != null)
                            {
                                return resourceReader.ReadToEnd();
                            }
                        }
                    }
                }
                return null;
            }
    
            #endregion
    
            public int GetLinksCount(Office.IRibbonControl Control)
            {
                return LinkMap.Count;
            }
    
            public string GetLinksLabel(Office.IRibbonControl Control, int Index)
            {
                List<string> keys = LinkMap.Keys.ToList<string>();
                return keys[Index];
            }
    
            public void LinkSelected(Office.IRibbonControl Control,string SelectId,
                int SelectIndex)
            {
                List<string> values = LinkMap.Values.ToList<string>();
                Process.Start("IExplore.exe", values[SelectIndex]);
            }
        }
    }

    Ribbon1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <customUI xmlns="http://schemas.microsoft.com/office/2009/07/customui" onLoad="Ribbon_Load">
      <ribbon>
        <tabs>
          <tab id="MyTab" label="MyTab">
            <group id="MyFavoriteLinks"
                   label="My Favorite Links">
              <dropDown id="FavoriteLinksDropDown" getItemCount ="GetLinksCount"
                        getItemLabel="GetLinksLabel" onAction="LinkSelected"/>
            </group>
          </tab>
        </tabs>
      </ribbon>
    </customUI>

    I hope it can help you.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by 许阳(无锡)Moderator Monday, May 7, 2012 7:31 AM
    • Unmarked as answer by Rad1 Tuesday, May 8, 2012 1:22 AM
    • Marked as answer by Rad1 Tuesday, May 8, 2012 1:22 AM
    Wednesday, May 2, 2012 5:21 AM
    Moderator
  • as for drag and drop onto ribbon surface - i think you are out of luck with that, but you could provide other means (i.e. ribbon button that will display winforms page/control that will accept drag and drop, so you can extend LinkMap collection and call Ribbon.InvalidateControl) that will achieve the same

    Wednesday, May 2, 2012 10:40 AM