.NET Coding Problem - Downloading Files

SaturnX

Diamond Member
Jul 16, 2000
3,415
0
76
Hey everyone,

Alright, right now I'm trying to download a file from a webserver and save it on the PC. I've gotten that part down, now this is where it's getting tricky for me.

I need to download this file continually (on a interval lets say, for updating purposes), however if I try and download the file again, I get an Exception.

Here's what I'm using right now:

Dim webc as New WebClient
webc.DownloadFile("http://somesite.com/random.xml", "c:\somefile.xml")

Now, if I execute this code once, it works fine, however if I execute it again, I get the following exception:

An unhandled exception of type 'System.Net.WebException' occurred in system.dll

Additional information: An exception occurred during a WebClient request.

It seems that the file is locked by the application, as even after it downloads I can't delete the file until I quit the application.

What would be a good way to get around this so I can continually overwrite the same file with a new file?

Thanks for your help!



 

SaturnX

Diamond Member
Jul 16, 2000
3,415
0
76
NM, figured it out.. I forgot to close the XMLreader that was reading in the file... silly me..

--Mark