{"id":1806,"date":"2011-08-12T11:33:22","date_gmt":"2011-08-12T03:33:22","guid":{"rendered":"http:\/\/www.sharepointboost.com\/blog\/?p=1806"},"modified":"2023-07-31T11:40:29","modified_gmt":"2023-07-31T03:40:29","slug":"different-ways-to-get-sharepoint-versions","status":"publish","type":"post","link":"https:\/\/www.boostsolutions.com\/blog\/different-ways-to-get-sharepoint-versions\/","title":{"rendered":"How to find SharePoint Version"},"content":{"rendered":"<p>SharePoint now has two major releases; they are SharePoint 2007 (with version 12.0) and SharePoint 2010 (with version 14.0). For developers, it&#8217;s important to know which version they are working on. Sometimes developers have to working on both and write different code for different version. <strong>Here are 5 ways to find SharePoint version.<\/strong><\/p>\n<p><strong><em>Find the version by SharePoint Object Model.<\/em><\/strong><br \/>\nThis is easy for all developers, using Microsoft.SharePoint.Administration namespace and gets the version information by following code.<\/p>\n<pre lang=\"csharp\">string version = SPFarm.Local.BuildVersion;\r\nConsole.WriteLine(version);<\/pre>\n<p>for SharePoint 2007, the output will be string starts with &#8220;12.0&#8221;; for SharePoint 2010, the output will be string starts with &#8220;14.0&#8221;.<\/p>\n<p><strong><em>Find the version by SharePoint Client Object Model.<br \/>\n<\/em><\/strong>This is only applied to SharePoint 2010 as SharePoint 2007 does not support this way.using Microsoft.SharePoint.Client name space and get version by following code.<\/p>\n<pre lang=\"csharp\">string url = @\"http:\/\/yourweburl\";\r\nClientContext context = new ClientContext(url);\r\ncontext.ExecuteQuery();\r\nConsole.WriteLine(context.ServerVersion.Major.ToString());<\/pre>\n<p>The output will be string &#8220;14&#8221;.<\/p>\n<p><strong><em>Finding the Version by SharePoint 2010 Management Shell<\/em><\/strong><br \/>\nSharePoint Management Shell provides another way to access SharePoint conveniently. We can use it to get SharePoint version from server. This is again applied to SharePoint 2010.<\/p>\n<pre lang=\"csharp\">$farm = [Microsoft.SharePoint.Administration.SPFarm]::Local\r\n$version = $farm.BuildVersion.ToString()<\/pre>\n<p>The output will start with &#8220;14.0&#8221; for SharePoint 2010.<\/p>\n<p><strong><em>Finding the version by HttpWebResponse object<\/em><\/strong><br \/>\nWe can send a web request to SharePoint and then get a host header. There is one host header <strong>MicrosoftSharePointTeamServices<\/strong> that will provide us with the SharePoint version. Following function will send request and return version.<\/p>\n<pre lang=\"csharp\">string GetSharePointVersion(string url, ICredentials credentials)\r\n{\r\n    string version = string.Empty;\r\n    try\r\n    {\r\n        Uri uri = new Uri(url);\r\n        HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);\r\n        request.AllowAutoRedirect = false;\r\n        request.Credentials = credentials;\r\n        HttpWebResponse response = (HttpWebResponse)request.GetResponse();\r\n        version = response.Headers[\"MicrosoftSharePointTeamServices\"].ToString();\r\n    }\r\n    catch (Exception)\r\n    {\r\n    }\r\n    return version;\r\n}<\/pre>\n<p>For SharePoint 2007, the return value will start with &#8220;12.0&#8221;; for SharePoint 2010, the return value will start with &#8220;14.0&#8221;.<\/p>\n<p><strong><em>Finding SharePoint version by reading registry<\/em><\/strong><br \/>\nWe can also get the SharePoint versions from Windows registry. If SharePoint is installed, following entry will be added in the registry (HKEY_LOCAL_MACHINE).<\/p>\n<p>For SharePoint 2007: &#8220;SOFTWARE\\Microsoft\\Shared Tools\\Web Server Extensions\\12.0&#8221;<br \/>\nFor SharePoint 2010: &#8220;SOFTWARE\\Microsoft\\Shared Tools\\Web Server Extensions\\14.0&#8221;<\/p>\n<p>And one key under entry is &#8220;Version&#8221; which stores the SharePoint version. So we can read it in registry by code:<\/p>\n<pre lang=\"csharp\">string GetSharePointVerions()\r\n{\r\n    string SharePoint2007InstallEntry = @\"SOFTWARE\\Microsoft\\Shared Tools\\Web Server Extensions\\12.0\";\r\n    string SharePoint2010InstallEntry = @\"SOFTWARE\\Microsoft\\Shared Tools\\Web Server Extensions\\14.0\";\r\n    string version = string.Empty;\r\n    RegistryKey key2007 = Registry.LocalMachine.OpenSubKey(SharePoint2007InstallEntry);\r\n    RegistryKey key2010 = Registry.LocalMachine.OpenSubKey(SharePoint2010InstallEntry)\r\n    if(key2007 != null)\r\n    {\r\n        object oValue = key2007.GetValue(\"Version\");\r\n        if (null != oValue)\r\n        {\r\n            version = oValue.ToString();\r\n        }\r\n    }\r\n    else if(key2010 != null)\r\n    {\r\n        object oValue = key2010.GetValue(\"Version\");\r\n        if (null != oValue)\r\n        {\r\n            version = oValue.ToString();\r\n        }\r\n    }\r\n    else{}\r\n    return version;\r\n}<\/pre>\n<p>For SharePoint 2007, the return value will be &#8220;12.0&#8221;; for SharePoint 2010, the return value will be &#8220;14.0&#8221;.<br \/>\n<img decoding=\"async\" alt=\"\" src=\"http:\/\/www.BoostSolutions.com\/blog\/wp-content\/uploads\/2011\/08\/version.jpg\" \/><br \/>\nBesides, we can use the same way to get 12 or 14 hive path by get the value of key &#8220;Location&#8221; under entry.<\/p>\n<p>Above are different ways to get SharePoint versions, we can use them to meet different requirements.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SharePoint now has two major releases; they are SharePoint 2007 (with version 12.0) and SharePoint 2010 (with version 14.0). For developers, it&#8217;s important to know which version they are working on. Sometimes developers have to working on both and write different code for different version. Here are 5 ways to find SharePoint version. Find the [&hellip;]<\/p>\n","protected":false},"author":22,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[125],"tags":[486,27,199],"_links":{"self":[{"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1806"}],"collection":[{"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/users\/22"}],"replies":[{"embeddable":true,"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/comments?post=1806"}],"version-history":[{"count":23,"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1806\/revisions"}],"predecessor-version":[{"id":9300,"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/posts\/1806\/revisions\/9300"}],"wp:attachment":[{"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/media?parent=1806"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/categories?post=1806"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.boostsolutions.com\/blog\/wp-json\/wp\/v2\/tags?post=1806"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}