|
-
Sep 3rd, 2008, 01:01 PM
#1
Thread Starter
Addicted Member
[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.
-
Sep 3rd, 2008, 01:39 PM
#2
Re: The proper way to retrieve file names from a path?
Have you checked what the ListBox1.SelectedItem.ToString is?
-
Sep 3rd, 2008, 01:48 PM
#3
Addicted Member
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'.
-
Sep 3rd, 2008, 01:55 PM
#4
Addicted Member
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?
-
Sep 3rd, 2008, 02:00 PM
#5
Thread Starter
Addicted Member
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.
-
Sep 3rd, 2008, 02:10 PM
#6
Re: The proper way to retrieve file names from a path?
is TextBox1.Text a valid path/filename?
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Sep 3rd, 2008, 02:24 PM
#7
Thread Starter
Addicted Member
Re: The proper way to retrieve file names from a path?
-
Sep 3rd, 2008, 02:54 PM
#8
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.
Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
- Abraham Lincoln -
-
Sep 3rd, 2008, 03:14 PM
#9
Thread Starter
Addicted Member
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|