Muhammad Raja
Muhammad Raja

Reputation: 2010

tree View fullpath stripping

Here is the application on codeplex all i did is created a new text box and trying to get path of current node selected into this text box, but i am getting extra things which i dont need at all,

Link to application,

Codeplex app

Code Line i am using is ,

TextBox1.Text = nodeCurrent.FullPath;

and output i am getting is something like this,

My Computer\C:\\Documents and Settings\Administrator\Desktop

My Computer here is Root Node, which i dont need, all i want is

C:\Documents and Settings\Administrator\Desktop

Picture added

enter image description here

Here is the function i am using it

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

Upvotes: 1

Views: 2560

Answers (2)

Abdul Hadi Sheikh
Abdul Hadi Sheikh

Reputation: 26

add the following line in the code and it will remove recurring "\" in the path

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

Upvotes: 1

Jim Mischel
Jim Mischel

Reputation: 133995

It looks to me like the getFullPath method in that code will do exactly what you want. It strips the MyComputer\ string and returns the rest. Write:

string newPath = getFullPath(nodeCurrent.FullPath);

Upvotes: 3

Related Questions