是否有可能找到浏览器托管应用程序(XBAP)运行的浏览器版本(例如IE6,IE7或IE8)?我想从XBAP中找到浏览器版本。
答案 0 :(得分:2)
在微软论坛的帮助下,我被引导到一个终于有效的方向。下面是C ++ .NET中的概念证明(。
using namespace System::Windows::Forms;
[STAThread]
String^ GetBrowserVersion() {
String^ strResult = String::Empty;
WebBrowser^ wb = gcnew WebBrowser();
String^ strJS = "<SCRIPT>function GetUserAgent() { return navigator.userAgent; }</SCRIPT>";
wb->DocumentStream = gcnew MemoryStream( ASCIIEncoding::UTF8->GetBytes(strJS) );
while ( wb->ReadyState != WebBrowserReadyState::Complete ) {
Application::DoEvents();
}
String^ strUserAgent = (String^)wb->Document->InvokeScript("GetUserAgent");
wb->DocumentStream->Close();
String^ strBrowserName = String::Empty;
int i = -1;
if ( ( i = strUserAgent->IndexOf( "MSIE" ) ) >= 0 ) {
strBrowserName = "Internet Explorer";
} else if ( ( i = strUserAgent->IndexOf( "Opera" ) ) >= 0 ) {
strBrowserName = "Opera";
} else if ( ( i = strUserAgent->IndexOf( "Chrome" ) ) >= 0 ) {
strBrowserName = "Chrome";
} else if ( ( i = strUserAgent->IndexOf( "FireFox" ) ) >= 0 ) {
strBrowserName = "FireFox";
}
if ( i >= 0 ) {
int iStart = i + 5;
int iLength = strUserAgent->IndexOf( ';', iStart ) - iStart;
strResult = strBrowserName + " " + strUserAgent->Substring( iStart, iLength );
}
return strResult;
}
答案 1 :(得分:1)
我认为你的意思是Silverlight而不是WPF? (它们是独立的技术,虽然相似)。
查看System.Windows.Browser.BrowserInformation
Class
具体地
System.Windows.Browser.BrowserInformation.BrowserVersion
从上面的MSDN页面:
using System;
使用System.Windows.Controls; 使用System.Windows.Browser;
public class Example
{
public static void Demo(System.Windows.Controls.TextBlock outputBlock)
{
outputBlock.Text +=
"\nSilverlight can provide browser information:\n"
+ "\nBrowser Name = " + HtmlPage.BrowserInformation.Name
+ "\nBrowser Version = " +
HtmlPage.BrowserInformation.BrowserVersion.ToString()
+ "\nUserAgent = " + HtmlPage.BrowserInformation.UserAgent
+ "\nPlatform = " + HtmlPage.BrowserInformation.Platform
+ "\nCookiesEnabled = " +
HtmlPage.BrowserInformation.CookiesEnabled.ToString() + "\n";
}
}
答案 2 :(得分:-1)
for (int rowIterator = 2; rowIterator <= noOfRow; rowIterator++)
{
var ex = new ExcelData();
ex.CostCode = workSheet.Cells[rowIterator, 1].Value.ToString();
ex.EmployeeNumber = workSheet.Cells[rowIterator, 2].Value.ToString();
ex.Class = workSheet.Cells[rowIterator, 3].Value.ToString();
ex.Date = workSheet.Cells[rowIterator, 4].Value.ToString();
ex.Hours = workSheet.Cells[rowIterator, 5].Value.ToString();
ex.PayType = workSheet.Cells[rowIterator, 6].Value.ToString();
dataList.Add(ex);
}