Reputation: 475
I am making a GUI file mover using Treeview, the only issue I am having is getting the absolute file path.
When I use this code:
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo sourceDir = new DirectoryInfo(textBox1.Text);
sourceDir.EnumerateFiles();
var fileToMovePath = Path.GetFullPath(treeView1.SelectedNode.FullPath);
var pathToMoveToo = textBox2.Text;
//File.Move(fileToMovePath, pathToMoveToo);
MessageBox.Show(fileToMovePath);
}
I get this file path:
Which obviously isn't what I want, as that file is actually stored on my desktop. Any ideas?
Upvotes: 0
Views: 1230
Reputation: 191
I was facing a similar problem and after some trial and error following solution worked for me.
Replace
var fileToMovePath = path.GetFullPath(treeView1.SelectedNode.FullPath);
With
var fileToMovePath = textBox1.Text + "\\" + treeView1.SelectedNode.Text;
I think the problem here was with path.GetFullPath(), that it was displaying the path to directory from where program is being executed and not the one we picked.
Upvotes: 2