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();
}
}
}