I have 2 methods in c#.
using Microsoft.Win32;
//other code
public static string GetOfficeVersion()
{
string version = Microsoft.Office.Interop.Outlook.Application().Version;
return version.Split('.')[0];
}
public static string GetOfficeVersionNew()
{
using (var key = Registry.ClassesRoot.OpenSubKey(@"Outlook.Application\CurVer"))
{
var value = key?.GetValue("").ToString() ?? "";
value = value.Replace("Outlook.Application.", "");
return $"{value}.0";
}
}
I tested them on outlook 2021 and got the number 16. I also tested them on outlook 2013 and got the number 15. I think there is something wrong in these methods. Can you please guide me the correct method to determine the outlook version considering it is required for outlook 2013, 2016, 2019 and 2021.
Now that Office apps are being continuously updated, the major version number will stay at 16. You'd need to look at the build numbers to distinguish between versions.
Outlook Object Model has not been modified in any meaningful way for years. If you are attempting to use properties/methods not available in all versions of Outlook, use reflection to check for their presence and invoke them.