這是我sample.htmlC#的NullReferenceException
<html>
<head>
<title>Test</title>
</head>
<body>
<div id="testingID">hello</div>
</body>
</html>
內,我有這樣的代碼在C#中,我想提示與該DIV元素的世界「你好」裏面ID testingID
private void btnGetData_Click(object sender, EventArgs e)
{
string url = string.Format("{0}/sample.html", Environment.CurrentDirectory);
WebBrowser webb = new WebBrowser();
webb.Navigate(url);
var doc = webb.Document;
HtmlElement elem = doc.GetElementById("testingID");
MessageBox.Show(elem.InnerText);
}
,但我得到對象引用不設置到對象的實例。 on MessageBox.Show(elem.InnerText);
這裏一點幫助..
感謝老闆..它就像一個魅力..:d –
很高興我能夠幫助:-) – Davita