1.在winform中使用IE:
在工具箱裡右擊,選添加/刪除選項,在彈出的對話方塊裡選Com組件選項卡,找到Microsof Web瀏覽器組件,確定,
在工具箱裡選擇WebBrowser控制項,拖放到表單上,然後寫代碼:
private void button1_Click(object sender, System.EventArgs e)
{
string str="";
System.Object nullObject=0;
System.Object nullObjStr=str;
this.axWebBrowser1.Navigate("www.csdn.net",ref nullObject,ref nullObjStr,ref nullObjStr,ref nullObjStr);
}
2.修改xml節點值:
設xml文檔為:
<test>
<name>server</name>
</test>
XmlDocument doc = new XmlDocument();
doc.Load("sample.xml");
XmlNodeList nodes = doc.GetElementsByTagName("name");
nodes[0].InnerText = "NewValue";
doc.Save("sample.xml");
3.在類被析構時向log檔案中寫內容:
using System;
using System.IO;
using System.Data;
namespace finalize
{
class test
{
string s = "aaa";
~test()
{
StreamWriter lastGasp;
lastGasp = File.CreateText("yourLog.log");
lastGasp.WriteLine("it's a log" + s);
lastGasp.Flush();
lastGasp.Close();
}
[STAThread]
static void Main(string[] args)
{
test t = new test();
}
}
}