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;
- }
- }
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()) {
- // 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";
- }
- }
- 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.
(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
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 See Also
Join the conversation! Your thoughts help the community grow.