• 0

[VB.NET] Simple Program to Copy a file to a remote location


Question

Good Evening!

So, just at home, thinking about work and we have a common problem that requires a certain file to be copied over to a remote computer. So I'm making a really basic program to simplify the task for us.

The idea of it is, we keep the file on the root of C: and it copies it to a remote computer to a specific directory. After doing a little research, here is the simple code I ended up with.

Dim strCompName As String = ""

        strCompName = TextBox1.Text

        My.Computer.FileSystem.CopyFile("C:\file.dll", "\\" & strCompName & "\C$\Program Files\otherlocation")



    End Sub
End Class


Simple right? Well I must be using the wrong call. To test it, because I don't have a domain computer at home, it fails out with an I/O error stating the following:

could not complete operation since a directory already exists in this path

On the domain at work, we have full rights to the machine that is if everything is going right, so impersonation or authentication isn't an issue as far as that goes, but I've never done anything like this in vb so don't know if it is required. Any ideas?

6 answers to this question

Recommended Posts

  • 0
  On 31/05/2010 at 16:26, MrBalladeer said:

Good Idea!

Is there a switch that even if it exists, to overwrite the file? I'm getting an IO Exception: "File already exists"

If I could get it to just overwrite it, I think I would be in business!

My.Computer.FileSystem.CopyFile("C:\file.dll", "\\" & strCompName & "\C$\Program Files\otherlocation\file.dll", True)

^ voila... that simple for overwrite. (Assuming you have write privs)

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.