蓝江传粤语:C#读取远端电脑文件的方法

来源:百度文库 编辑:中财网 时间:2024/07/08 18:36:33

转自:http://hi.baidu.com/%BA%BA%BB%AF%C0%CB%D7%D3/blog/item/0664bc01ba5d338de850cd73.html

using System.Management;

using System.IO;

在你的事件中添加如下代码

        ConnectionOptions conn = new ConnectionOptions();

        conn.Username = "Administrator";//登入远端电脑的账户

        conn.Password = "hanroc";//登入远端电脑的密码

        ManagementPath path = new ManagementPath();

        //其中root\cimv2是固定写法

        path.Path = @"\\172.26.41.1\root\cimv2";

        ManagementScope ms = new ManagementScope();

        ms.Options = conn;

      ms.Path = path;

        ms.Connect();

        //这里的例子读取文件的最后修改日期

        ObjectQuery query =

            new ObjectQuery("SELECT * FROM CIM_DataFile "+

            "WHERE Name = 'C:\\\\KVOffice.log'");

        ManagementObjectSearcher searcher =

            new ManagementObjectSearcher(ms,query);

        ManagementObjectCollection collection = searcher.Get();

        string time = "";

        foreach (ManagementObject obj in collection)

        {

            time =

                obj.Properties["LastModified"].Value.ToString().
                Substring(0,14);

        }

        Response.Write(time); C# 读写XML                http://blog.csdn.net/harry8033/archive/2009/05/07/4157554.aspx http://blog.163.com/ajunsj/blog/static/106753420094128361615/                C# 读写XML类      http://www.cnblogs.com/soonfly/articles/1312567.html http://blog.csdn.net/andyhebear/archive/2008/07/21/2683047.aspx http://hi.baidu.com/oscarzq/blog/item/3835721e42caacf31ad576b4.html C# 操作XML实例 C#通用类实现 读取xml控制Asp.net控件输入信息长度(TextBox,FileUpload......)  XML 通用类:http://bbs.51js.com/viewthread.php?tid=79183 获取XML节点属性值实例: XmlDocument xmlDoc = new XmlDocument();
 xmlDoc.LoadXml("

");
XmlNode xmlNode = xmlDoc.SelectSingleNode("plist/p");
Page.Response.Write(xmlNode.Attributes["id"].Value);  XML文件格式            

  

 

 

  

  
           C#修改XML节点的值 XmlDocument MyXml = new XmlDocument();
            MyXml.Load(@"Config.xml");
            //获取节点的所有子节点
            XmlNodeList MyNodeList = MyXml.SelectSingleNode("Rule").ChildNodes;
            //遍历下的所有子节点
            foreach (XmlNode MyNode in MyNodeList)
            {
                if (MyNode.Name == "InfoPage")
                {
                    XmlNodeList InfoPageNodeList = MyNode.ChildNodes;                     //遍历InfoPage节点
                    foreach (XmlNode InfoPageNode in InfoPageNodeList)
                    {
                        if (InfoPageNode.Name == "BookClass")
                        {
                            InfoPageNode.InnerText = "玄幻魔法";
                            break;
                        }
                    }
                    break;
                   
                }                 MyXml.Save(@"Config.xml"); //保存