标签:files new 使用 tostring director button start proc system
String Path = "C:\\Test"; private void ListDirectory(TreeView treeView, string path) { treeView.Nodes.Clear(); var rootDirectoryInfo = new DirectoryInfo(path); treeView.Nodes.Add(CreateDirectoryNode(rootDirectoryInfo)); } private static TreeNode CreateDirectoryNode(DirectoryInfo directoryInfo) { var directoryNode = new TreeNode(directoryInfo.Name); foreach (var directory in directoryInfo.GetDirectories()) directoryNode.Nodes.Add(CreateDirectoryNode(directory)); foreach (var file in directoryInfo.GetFiles()) directoryNode.Nodes.Add(new TreeNode(file.Name) { Tag = file }); return directoryNode; } private void button1_Click(object sender, EventArgs e) { //string s = treeView1.SelectedNode.ToString(); //String TreeNodeName = treeView1.SelectedNode.ToString().Replace("TreeNode: ", String.Empty); //System.Diagnostics.Process.Start(Path + "\\" + TreeNodeName); string p = (treeView1.SelectedNode?.Tag as FileInfo)?.FullName; if (p != null) { System.Diagnostics.Process.Start(p); } } private void button2_Click(object sender, EventArgs e) { ListDirectory(treeView1, Path); }
标签:files new 使用 tostring director button start proc system
原文地址:https://www.cnblogs.com/jizhiqiliao/p/10456560.html