none
Finding out the Office Version while constructing a Ribbon RRS feed

  • Question

  • Hi all,

    I am writing a VSTO4 Outlook Add-in for Office 2007/10.

    My code requires a ribbon group to be added to the insepector.  However to correctly position the Ribbon group I have to know the Office version, so I can place the location correctly.  Currently I have a very dirty (or clever) solution using reflection.

    Is there a better way of doing this? 

    My code is currently:

    int iOfficeVersion = 12;
    			// This is a horrible way to discover what version of office is running
    			try
    			{
    				FieldInfo fi = Globals.Factory.GetType( ).BaseType.GetField( "_officeVersion", BindingFlags.NonPublic | BindingFlags.Instance );
    				if ( fi != null )
    				{
    					iOfficeVersion = Convert.ToInt32( fi.GetValue( Globals.Factory ) );
    				}
    			}
    			catch
    			{
    			}
    			if( iOfficeVersion == 12 )
    			{
    				this.BrainloopGroup.Position = this.Factory.RibbonPosition.BeforeOfficeId( "GroupInclude" );
    			}
    			else
    			{
    				this.BrainloopGroup.Position = this.Factory.RibbonPosition.BeforeOfficeId( "GroupIncludeMainTab" );
    			}

    Any ideas?


    Tuesday, August 14, 2012 8:02 AM

Answers

  • Whether or not these are better ideas, they are alternatives.
     
    Code I use to check for a running instance of Outlook and grab a handle to the instance:
     

    System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");

    int collCount = processes.Length;

    if (collCount != 0)

    {

    // Outlook already running, hook into the Outlook instance

    outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

    }

    Once you have an Outlook.Application object you can check the Version string as Damian suggested.
     
    An alternative might be to check the registry at HKCR\Outlook.Application\ or in its subkey of CurVer. For Outlook 2010 you'd find something like "Microsoft Outlook 14.0 Object Library" and at CurVer something like "Outlook.Application.14".

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:ec34ad6f-8553-4984-b924-3793735d5234...

    in ribbon xml thisaddin is always called before. I guess you have to live with your hack unless someone else will have some idea.


    Ken Slovak MVP - Outlook
    • Marked as answer by Keith Ball Tuesday, August 14, 2012 1:18 PM
    Tuesday, August 14, 2012 1:16 PM

All replies

  • Check Application.Version string
    Tuesday, August 14, 2012 8:14 AM
  • Check Application.Version string

    Application is not accesible at that time.

    Globals.ThisAddIn has not yet been initialised.

    Tuesday, August 14, 2012 8:15 AM
  • you said you need this for inspector window and thisaddin class was not instantiated yet? you have no access to Application object?
    Tuesday, August 14, 2012 8:51 AM
  • you said you need this for inspector window and thisaddin class was not instantiated yet? you have no access to Application object?

    Yip.  Globals.ThisAddIn is null when trying to access it when using the Ribbon (Designer).

    My code from above is in InitializeComponent().

    partial class NewMailMessageRibbon : Microsoft.Office.Tools.Ribbon.RibbonBase <snip> private void InitializeComponent( ) { <snip>

    My code from above


    Tuesday, August 14, 2012 8:56 AM
  • in ribbon xml thisaddin is always called before. I guess you have to live with your hack unless someone else will have some idea.

    Tuesday, August 14, 2012 9:44 AM
  • Whether or not these are better ideas, they are alternatives.
     
    Code I use to check for a running instance of Outlook and grab a handle to the instance:
     

    System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK");

    int collCount = processes.Length;

    if (collCount != 0)

    {

    // Outlook already running, hook into the Outlook instance

    outlookApp = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;

    }

    Once you have an Outlook.Application object you can check the Version string as Damian suggested.
     
    An alternative might be to check the registry at HKCR\Outlook.Application\ or in its subkey of CurVer. For Outlook 2010 you'd find something like "Microsoft Outlook 14.0 Object Library" and at CurVer something like "Outlook.Application.14".

    --
    Ken Slovak
    [MVP-Outlook]
    http://www.slovaktech.com
    Author: Professional Programming Outlook 2007
    "DamianD" <=?utf-8?B?RGFtaWFuRA==?=> wrote in message news:ec34ad6f-8553-4984-b924-3793735d5234...

    in ribbon xml thisaddin is always called before. I guess you have to live with your hack unless someone else will have some idea.


    Ken Slovak MVP - Outlook
    • Marked as answer by Keith Ball Tuesday, August 14, 2012 1:18 PM
    Tuesday, August 14, 2012 1:16 PM
  • Thanks for the input.  It looks there is not a "right" way to do this.  I'll just live with what I've got until it stops working.
    • Edited by Keith Ball Tuesday, August 14, 2012 1:19 PM
    Tuesday, August 14, 2012 1:19 PM