Question Getting error when downloading file and file already exists

Joebu

Member
Joined
Mar 12, 2010
Messages
5
Programming Experience
Beginner
Greetings all. I am totally new to vs2008 and programming in general so please bear with me.

I have a menu item called Update that uses this code when clicked:

Private Sub UpdateDatabaseToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UpdateDatabaseToolStripMenuItem.Click
My.Computer.Network.DownloadFile _
("http://www.mysitecom/downloads/data/test.xls", _
"C:\test\test.xls", False, 500)
End Sub


It works great except for the fact that if the file already exists I get an error. Is there a way to write the code to overwrite the C:\test\test.xls file?

Also clicking the menu item when a file is not located on the web also gives an error and halts the program. From my understand I will need to write an exception handler.

Any quick tips will be greatly appreciated.
 
You parameters are incorrect. There is no overloaded method for this accepting 4 parameters fitting the values you are passing. Either correc this and/or check if the file exists before starting the download. Delete the file if it does then perform the download.
 
Thanks Tom. The information you provided was very helpful. I did as you suggested and had the program check for the file and if it was there delete it before downloading the new one.
I appreciate your time.
 
Back
Top