Detect the Installed SharePoint 2016 Edition Using C#

In this article, I will show how to

Detect the SharePoint 2016 Edition and the Farm Build Number using C#.


Detecting the SharePoint Edition via c# is not just line of code as detecting the SharePoint Build Number!

To detect the SharePoint 2016 Edition, it requires knowing the corresponding SKU.

The Stock Keeping Unit (SKU) is a unique set of characters identification code for a particular product/service. Read more at SKU.)


Get SharePoint 2016 Edition using C#

Based on the installed product SKU, you can detect the corresponding SharePoint 2016 Edition via C# as the following:


public string Get_SPEdition()
{
try
{
string edition = "";
SPSecurity.RunWithElevatedPrivileges(delegate()
{
var editionguid = SPFarm.Local.Products;
foreach (var item in editionguid)
{
switch (item.ToString().ToUpper())
{
// SharePoint 2016
case "5DB351B8-C548-4C3C-BFD1-82308C9A519B":
edition = "SharePoint Server 2016 Trail.";
break;
case "4F593424-7178-467A-B612-D02D85C56940":
edition = "SharePoint Server 2016 Standard.";
break;
case "716578D2-2029-4FF2-8053-637391A7E683":
edition = "SharePoint Server 2016 Enterprise.";
break;
default: edition = "The SharePoint Edition can't be determined.";
break;
}
}
});

return edition;
}
catch (Exception)
{
return "An error occurred! Make sure that\r\n- The SharePoint is installed";
}
}

In case, it’s

  • 5DB351B8-C548-4C3C-BFD1-82308C9A519B, So The Installed SharePoint Edition is SharePoint 2016 Trail.
  • 4F593424-7178-467A-B612-D02D85C56940, So The Installed SharePoint Edition is SharePoint 2016 Standard.
  • 716578D2-2029-4FF2-8053-637391A7E683, So The Installed SharePoint Edition is SharePoint 2016 Enterprise.

Get SharePoint 2016 Build Number using C#

The below function “Get_SPVersion” is used to detect the Farm Build Number.


public string Get_SPVersion()
{
try
{
return SPFarm.Local.BuildVersion.ToString();
}
catch (Exception)
{
throw;
}
}

Output

(Test1) The SharePoint 2016 installed, the result should look like

Detect SharePoint 2016 Edition using C#


(Test2)
 You don’t have SharePoint 2016 installed but you have other SharePoint version, the result should look like

Detect SharePoint 2016 SKU using C#


(Test3)
 The SharePoint is not installed, the result should look like

Detect SharePoint Edition using C#


Applies To
  • SharePoint 2016.
Download
  • Download the source code from TechNet Gallery “Detect SharePoint 2016 Edition Solution “.
  • In case, you need to run only the execution file, you should get it at this location “\SharePoint 2016 Edition Detection\bin\Debug\SharePoint_Edition_Detection.exe”
Conclusion

In this article, I have explained how to detect the SharePoint 2016 Edition and the Farm Build Number via Server Side Object Model – C#.

See Also
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s