[RESOLVED] The proper way to retrieve file names from a path?
Hi, I'm using this to retrieve a file name from a path:
Code:
Dim fullPath As String = TextBox1.Text
Dim fileName As String = IO.Path.GetFileName(fullPath)
However, when I put it to use using something like this:
Code:
IO.File.Copy(TextBox1.Text, ListBox1.SelectedItem.ToString + "PSP\THEME\" + fileName)
I get the 'NullReferenceException' error :( Can somebody help me with this?
I'm sure it's just something I'm missing.
Re: The proper way to retrieve file names from a path?
Have you checked what the ListBox1.SelectedItem.ToString is?
Re: The proper way to retrieve file names from a path?
I'm not sure I follow what you are asking, so I'm probably being useless here, but what the heck.
Code:
myString = Application.ProductName & ".exe"
That will put your executables name in 'myString'.
Re: The proper way to retrieve file names from a path?
For your attempt run the code that results in the exception, what are the values in fullPath, fileName and ListBox1.SelectedItem.ToString?
Re: The proper way to retrieve file names from a path?
I probably should have said that my listbox displays drive letters like 'C:\'. I just can't see what's wrong with the code.
Re: The proper way to retrieve file names from a path?
is TextBox1.Text a valid path/filename?
Re: The proper way to retrieve file names from a path?
Re: The proper way to retrieve file names from a path?
It's most likely that there isn't an item selected in your listbox when you run that code... And since there is none selected, ListBox1.SelectedItem property returns Nothing on which you try to call the ToString method and so it results in a null reference exception.
Re: The proper way to retrieve file names from a path?
Hmmm... I've just found something weird, on my development computer, it doesn't work but on another computer, it does :S
Oh well, I guess it's resolved, thank you for your suggestions anyway :)
stanav, I did have an item selected.