Exemplo n.º 1
0
 private TreeNode GetFileNode(string text)
 {
     var filename = Path.GetFileName(text);
     var result = new TreeNode(filename);
     var content = new NetworkNode(text, NodeType.File);
     result.ToolTipText = content.ToString();
     result.Tag = content;
     return result;
 }
Exemplo n.º 2
0
        private void btnConnect_Click(object sender, EventArgs e)
        {
            IPAddress ip = null;
            if (!IPAddress.TryParse(txtIP.Text, out ip))
            {
                MessageBox.Show("IP地址非法,请重新输入!");
                return;
            }
            this.btnConnect.Text = "请稍候...";
            this.btnConnect.Enabled = false;
            this.treeView1.Nodes.Clear();

            try
            {
                WmiShareFunction.RemoveShareNetConnect(ip.ToString(), connectionName, txtUsername.Text, txtPassword.Text);
                WmiShareFunction.CreateShareNetConnect(ip.ToString(), connectionName, txtUsername.Text, txtPassword.Text);
                foreach (var diskChar in alphabet)
                {
                    var remoteDir = string.Format(@"\\{0}\{1}$", ip, diskChar);
                    try
                    {
                        var directories = Directory.GetDirectories(remoteDir);
                        var content = new NetworkNode(remoteDir, NodeType.Directory);
                        var diskNode = new TreeNode(remoteDir)
                        {
                            ToolTipText = content.ToString(),
                            Tag = content,
                        };
                        diskNode.BackColor = Color.Yellow;
                        this.treeView1.Nodes.Add(diskNode);
                    }
                    catch (Exception)
                    {
                    }
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            if (this.treeView1.Nodes.Count == 0)
            {
                MessageBox.Show(string.Format("获取{0}的磁盘信息失败,请重试!", ip), "Tip", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            this.btnConnect.Text = "连接";
            this.btnConnect.Enabled = true;
            this.treeView1.Enabled = true;
            //this.btnOK.Enabled = true;
        }
Exemplo n.º 3
0
 private TreeNode GetDirectoryNode(string text)
 {
     var leaveDir = text.Split(Path.DirectorySeparatorChar).Last();
     var result = new TreeNode(leaveDir);
     var content = new NetworkNode(text, NodeType.Directory);
     result.ToolTipText = content.ToString();
     result.Tag = content;
     result.BackColor = Color.Yellow;
     return result;
 }