Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 树视图全路径剥离_C#_.net_Winforms_Treeview - Fatal编程技术网

C# 树视图全路径剥离

C# 树视图全路径剥离,c#,.net,winforms,treeview,C#,.net,Winforms,Treeview,这是codeplex上的应用程序我所做的就是创建一个新的文本框,并尝试将当前节点的路径选择到这个文本框中,但我得到了我根本不需要的额外东西 链接到应用程序 我使用的代码行是 TextBox1.Text = nodeCurrent.FullPath; 我得到的输出是这样的 我的电脑\C:\\Documents and Settings\Administrator\Desktop 我的电脑是根节点,我不需要它,我想要的只是 C:\Documents and Settings\Administra

这是codeplex上的应用程序我所做的就是创建一个新的文本框,并尝试将当前节点的路径选择到这个文本框中,但我得到了我根本不需要的额外东西

链接到应用程序

我使用的代码行是

TextBox1.Text = nodeCurrent.FullPath;
我得到的输出是这样的

我的电脑\C:\\Documents and Settings\Administrator\Desktop

我的电脑是根节点,我不需要它,我想要的只是

C:\Documents and Settings\Administrator\Desktop

图片添加

这是我正在使用的函数

private void tvFolders_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
    {
        //Populate folders and files when a folder is selected
        this.Cursor = Cursors.WaitCursor;

        //get current selected drive or folder
        TreeNode nodeCurrent = e.Node;
        string newPath = getFullPath(nodeCurrent.FullPath);
        tbDirectory.Text = newPath;


        //clear all sub-folders
        nodeCurrent.Nodes.Clear();

        if (nodeCurrent.SelectedImageIndex == 0)
        {
            //Selected My Computer - repopulate drive list
            PopulateDriveList();
        }
        else
        {
            //populate sub-folders and folder files
            PopulateDirectory(nodeCurrent, nodeCurrent.Nodes);
        }
        this.Cursor = Cursors.Default;
    }

在我看来,该代码中的
getFullPath
方法将完全满足您的要求。它去掉
MyComputer\
字符串并返回其余的。写:

string newPath = getFullPath(nodeCurrent.FullPath);

在我看来,该代码中的
getFullPath
方法将完全满足您的要求。它去掉
MyComputer\
字符串并返回其余的。写:

string newPath = getFullPath(nodeCurrent.FullPath);

在代码中添加以下行,它将删除路径中重复出现的“\”

newPath = newPath.Replace("\\\\", "\\");

在代码中添加以下行,它将删除路径中重复出现的“\”

newPath = newPath.Replace("\\\\", "\\");

检查
Jim Mischel的回答,因为文章中有一种方法与我建议的做相同的事情。检查
Jim Mischel的回答,因为文章中有一种方法与我建议的做相同的事情。我的问题解决了一半,现在如何去掉“C:\\”后面的“\”因为我只需要一个&我怀疑我是否可以删除它,因为当我只单击驱动器c节点时,它会给我“c:/”但当我转到子文件夹(如文档)时,它会给我c://Documents@TimeToThine:我在代码中没有看到任何东西会使它变成双反斜杠。你看到界面上显示的“\\”了吗?我添加了图片,先生,它看起来怎么样like@TimeToThine:您只需在调试器中执行一步,即可查看从何处获取额外的“\”字符。粗略地看一下源代码,我什么也看不出来。@尝试调试时,只注意到一件事,它将驱动器名设置为“C:/”,然后当它添加路径时,需要立即删除它,brb如果我的问题解决了,现在如何去掉“C:\\”后面的“\”因为我只需要一个&我怀疑我是否可以删除它,因为当我只单击驱动器c节点时,它会给我“c:/”但当我转到子文件夹(如文档)时,它会给我c://Documents@TimeToThine:我在代码中没有看到任何东西会使它变成双反斜杠。你看到界面上显示的“\\”了吗?我添加了图片,先生,它看起来怎么样like@TimeToThine:您只需在调试器中执行一步,即可查看从何处获取额外的“\”字符。粗略地看一下源代码,我什么也看不出来。@尝试调试时,只注意到一件事,它将驱动器名设置为“C:/”,然后当它向其添加路径时,需要立即将其删除,brb