You can easily get the SharePoint Build Number via C# as shown below.
- public string Get_SPVersion() {
- try {
- return SPFarm.Local.BuildVersion.ToString();
- } catch (Exception) {
- throw;
- }
- }
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.
- public string Get_SPEdition() {
- try {
- string edition = "";
- SPSecurity.RunWithElevatedPrivileges(delegate() {
- var editionguid = SPFarm.Local.Products;
- foreach(var item in editionguid) {
- switch (item.ToString().ToUpper()) {
-
- 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, 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
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