Error: String Cannot Be Of Zero Length

I have a program that should copy files based on listbox selection. Due to the entire path being in listbox I was trying to strip the path out for another variable. My code is below.

What is causing the error:

String Cannot be of zero length. Parameter Name: OldValue
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Me.ProgressBar1.Maximum = 6
        Me.ProgressBar1.Minimum = 0
        Me.ProgressBar1.Value = 0

        Dim sourceRoot As String = SearchLocation.Text
        Dim destinationRoot As String = Review.Text

        Dim FilePath As String
        Dim newfile As String

        newfile = ListBox9.SelectedItem.ToString().Replace(SearchLocation.Text, Review.Text)

        If System.IO.File.Exists(ListBox9.SelectedItem) Then System.IO.File.Copy(ListBox9.SelectedItem, newfile)

        ProgressBar1.Value = +6

    End Sub

Open in new window

Who is Participating?
lazyberezovskyConnect With a Mentor Commented:
Error says that you have no text in SearchLocation.Text.
So, you cannot replace nothing with something:
ListBox9.SelectedItem.ToString().Replace(SearchLocation.Text, Review.Text)
MaxDes101Author Commented:
For reference the review and search location text is populated by a checkmark being checked... with a path as in c:\ or J:\
All Courses

From novice to tech pro — start learning today.