File Copying

Greetings, I am writing code that allows a user to copy a selected file.

My problem is that when I check to see if the file exists, I get an error saying the file not accessible because it is currentlly in use by another process.

Dim fsrc As New FileInfo(txtSource.Text)
Dim fdes As New FileInfo(txtDestination.Text)

If fsrc.Exists Then
If MessageBox.Show("File exists, overwrite ", "Overwrite ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) = Windows.Forms.DialogResult.Yes Then
fsrc.CopyTo(fdes.FullName & "\" & fsrc.Name, True)
Else
Exit Sub
End If
End If

Anyone know why There should not be another process using it.

Is it saying that my program is using it If so, how can I correct the problem so that it DOES copy when the user clicks "Yes"

Thanks in advance!



Answer this question

File Copying

  • Wim Bouma

    hi,

    your code working fine with me without any problem, but what i don't understand is this part

    Dim fdes As New FileInfo(txtDestination.Text)

    why don't you read the textbox value direclty in

    fsrc.CopyTo(txtDestination.Text & "\" & fsrc.Name, True)

    hope this helps



  • dhino

    Can anyone help me with this I keep getting the aforementioned error and I can't go any further in the development of this app. I have administrator rights, so that can't be the problem. Anyone from Microsoft have any ideas

  • peterhal

    No dice. It keeps throwing me the same error. That another process is using the file.

    I was using the variables for the paths because I had originally written subs and functions to process these instructions, so I passed the txtbox's text as a parameter. That is why I am not using the direct value from the txtbox.

  • File Copying