Checking the edition of Visio 2010 at runtime


I thought I would share a common function that I use in all of my add-ins to help me determine if Visio is of the correct version and edition in order for my add-in to execute properly.

Copy and paste this into Visual Studio…

/// <summary>
/// Gets a value indicating whether the correct Version of Visio is installed.
/// <para></para>
/// Visio 2010 (14) or > and the Edition has to be anything other than STD.
/// </summary>
internal bool IsVisio14NotSTDInstalled
{
    get
    {
        bool retVal = false;

        // the installed version of Visio has to be 14 or > and the edition has to be PRO or >
        if (this.Application.TypelibMinorVersion >= 14)
        {
            if (this.Application.CurrentEdition != Microsoft.Office.Interop.Visio.VisEdition.visEditionStandard)
            {
                retVal = true;
            }
        }

        return retVal;
    }
}

Here is an example showing how I call this from the Startup handler in the ThisAddin class (VSTO based add-in)…

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    ...

    // check for Visio 2010 > and Edition >= PRO

    if (!this.IsVisio14NotSTDInstalled)

    {

        MessageBox.Show(

            Globals.ThisAddIn.VisioApplicationWindow,

            Properties.Resources.VisioVersionNotSupported_Message,

            Properties.Resources.errorAddin_Caption,

            MessageBoxButtons.OK,

            MessageBoxIcon.Error);

        return;

    }

    ...

 

I perform this check at runtime because it is possible for the user to uninstall Visio and install another edition or version of Visio after the add-in is already installed on the system.  This is not a scenario that is common but it is still a nice check to help keep your add-in from failing or throwing exceptions in the event that this ever occurs.