The CRM SDK DLLs can easily connect to different CRM versions, for example the CRM 2013 DLLs can be used also with CRM 2011/2015 environments.
Depending the version some messages (like the ExecuteMultipleRequest) are not available, the following function returns an enumerator with the current CRM version.
Depending the version some messages (like the ExecuteMultipleRequest) are not available, the following function returns an enumerator with the current CRM version.
public enum CRMVersion
{
Unknown,
CRM2011,
CRM2011UR12PLUS,
CRM2013,
CRM2013SP1,
CRM2015
}
public CRMVersion GetCRMVersion(IOrganizationService service)
{
RetrieveVersionRequest versionRequest = new RetrieveVersionRequest();
RetrieveVersionResponse versionResponse = (RetrieveVersionResponse)service.Execute(versionRequest);
string version = versionResponse.Version;
if (version.StartsWith("5"))
{
try
{
int buildNumber = Convert.ToInt32(version.Substring(version.LastIndexOf(".") + 1));
if (buildNumber > 3000) { return CRMVersion.CRM2011UR12PLUS; }
}
catch { }
return CRMVersion.CRM2011;
}
if (version.StartsWith("6.0")) { return CRMVersion.CRM2013; }
if (version.StartsWith("6.1")) { return CRMVersion.CRM2013SP1; }
if (version.StartsWith("7")) { return CRMVersion.CRM2015; }
return CRMVersion.Unknown;
}
