Find The Installed SharePoint 2016 Edition Via C#

You can easily get the SharePoint Build Number via C# as shown below.

  1. public string Get_SPVersion() {  
  2.     try {  
  3.         return SPFarm.Local.BuildVersion.ToString();  
  4.     } catch (Exception) {  
  5.         throw;  
  6.     }  
  7. }  
But, have you ever tried to detect the SharePoint Edition via C#? Well, regardless of the answer, detecting the SharePoint Edition via C# is not just a line of code as Build Number. To detect the SharePoint 2016 Edition, it will require knowing the corresponding SKU. 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 via C#

Based on the installed product SKU, you can detect the corresponding SharePoint 2016 Edition programmatically, as the following.

  1. public string Get_SPEdition() {  
  2.     try {  
  3.         string edition = "";  
  4.         SPSecurity.RunWithElevatedPrivileges(delegate() {  
  5.             var editionguid = SPFarm.Local.Products;  
  6.             foreach(var item in editionguid) {  
  7.                 switch (item.ToString().ToUpper()) {  
  8.                     // SharePoint 2016  
  9.                     case "5DB351B8-C548-4C3C-BFD1-82308C9A519B":  
  10.                         edition = "SharePoint Server 2016 Trail.";  
  11.                         break;  
  12.                     case "4F593424-7178-467A-B612-D02D85C56940":  
  13.                         edition = "SharePoint Server 2016 Standard.";  
  14.                         break;  
  15.                     case "716578D2-2029-4FF2-8053-637391A7E683":  
  16.                         edition = "SharePoint Server 2016 Enterprise.";  
  17.                         break;  
  18.                     default:  
  19.                         edition = "The SharePoint Edition can't be determined.";  
  20.                         break;  
  21.                 }  
  22.             }  
  23.         });  
  24.         return edition;  
  25.     } catch (Exception) {  
  26.         return "An error occurred! Make sure that\r\n- The SharePoint is installed";  
  27.     }  
  28. }  
In case, it’s
  • 5DB351B8-C548-4C3C-BFD1-82308C9A519B, the installed SharePoint Edition is SharePoint 2016 Trial.
  • 4F593424-7178-467A-B612-D02D85C56940, the installed SharePoint Edition is SharePoint 2016 Standard.
  • 716578D2-2029-4FF2-8053-637391A7E683, the installed SharePoint Edition is SharePoint 2016 Enterprise.
Output

(Test1) You have SharePoint 2016 installed. The result should look like -

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

(Test3) You don’t have any SharePoint version installed, the result should look like -



Applies to

SharePoint 2016.

Download

Download the source code from “Detect SharePoint 2016 Edition Solution“.

Conclusion

In this article, we have learned how to detect the SharePoint 2016 Edition and the Farm Build Number via Server-side Object Model in C#.

Reference

Detect the Installed SharePoint 2016 Edition via C#

See Also