Get current Silverlight client version?

I want to know if there is a way to use C # to get the current version of Silverlight, which the user launches when opening the client of the application that I am developing.

It is intended for journaling.

I want to know if they use Silverlight 3 or 4 in their browsers

+3
source share
3 answers
var dotNetRuntimeVersion = Deployment.Current.RuntimeVersion;
var silverlightVersion = Environment.Version.ToString();

Supported in: 5, 4, 3

+2
source

Using C # I just don’t know, but what you could do is detect it using javascript and then send an ajax request to a function that lets the server know which version.

http://www.apijunkie.com/APIJunkie/blog/post/2009/04/How-to-programmatically-detect-Silverlight-version.aspx

script 4.0, .

0

Environment.Version . Silverlight 4, , , , , .

Silverlight Plugin JS, JS Silverlight. , : http://www.visiblox.com/blog/posts/2010/04/29/determining-silverlight-version-installed/ :

var pScriptElement = HtmlPage.Document.CreateElement("script");
pScriptElement.SetAttribute("type", "text/javascript");
pScriptElement.SetProperty("text", "function GetSilverlightVersion(){var parts = Array(\"ver-major\", \"ver-minor\", \"ver-build\", \"ver-revision\");var nav = navigator.plugins[\"Silverlight Plug-In\"];var versionStr = \"\";if (nav) {versionStr = nav.description;} else {if(SilverlightIsInstalledOnIE)versionStr = GetSilverlightVersionOnIE();else versionStr = -1;}return versionStr;}function SilverlightIsInstalledOnIE(version){if(version == null)version = \"1.0\";var AgControl = new ActiveXObject(\"AgControl.AgControl\");    if(AgControl == null)return false;elsereturn AgControl.isVersionSupported(version);}function GetSilverlightVersionOnIE(){var currVersion = Array(1,0,0,0);for(var i=0;i<currVersion.length;i++){currVersion[i] = FindSupportedMaxVersionOnIE(currVersion, i,0,10000000);}return GetVersionString(currVersion);}function GetVersionString(versionArr,currVersion,index){if(index == null)index = -1;var versionStr = \"\";for(var i=0;i<versionArr.length;i++){if(i>0)versionStr += \".\";if(i==index)versionStr +=currVersion;elseversionStr += versionArr[i];}return versionStr;}function FindSupportedMaxVersionOnIE(versionArr, index,bottom,top){if(bottom >= top){return bottom;}var currVersion = bottom;var prevVersion = currVersion;var step = 1;while(currVersion<top){if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,currVersion,index))){prevVersion = currVersion;currVersion += step;step *= 2;}elsereturn FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,currVersion-1)}if(SilverlightIsInstalledOnIE(GetVersionString(versionArr,top,index)))return top;elsereturn FindSupportedMaxVersionOnIE(versionArr, index,prevVersion,top-1)}");
HtmlPage.Document.Body.AppendChild(pScriptElement);

var slVer = HtmlPage.Window.Invoke("GetSilverlightVersion", null);

Thus, I was able to get a reliable version of the plugin for IE and other browsers. I created my own class for parsing and comparing versions, so I can easily check if the user is using the plugin before fixing it or with a known bug.

0
source

Source: https://habr.com/ru/post/1744017/


All Articles