Free Up File

Invisionsoft

Well-known member
Joined
Apr 20, 2007
Messages
64
Location
United Kingdom
Programming Experience
1-3
Hello.

I am using a webclient to download a file to my hard-drive. Every 10 minutes using a timer I want it to redownload the image (it is constantly changing). However using a webclient once time seems to lock the file even if i dispose it. So I cannot re-write the file in 10 minutes. The innerexception was "The process cannot access the file thing.jpg because it is being used by another process". There are no other processes using it (I have checked using Unlocker). Is there a way to free the image from the webclient, or use a different way to download the image (NB. I do not have access to FTP server for this site). Also, could setting the image as a backgroundimage to a panel be the culpret?

Regards
Invisionsoft
 
Webclient doesn't lock the file apart from when it writes the file.
Also, could setting the image as a backgroundimage to a panel be the culpret?
If you used Image.FromFile to load the image to control it has locked it, see post 2 here for a code sample for loading it from stream.
 
Thanks

Thankyou, that freed up my file lock problem, however it looks like another has sprung up (or I just noticed it)

I am using this code to download the file.

VB.NET:
Dim url As String = "http://dealextreme.com/productimages/sku_" + sku + "_1.jpg/"
            Dim wc As New System.Net.WebClient
            wc.DownloadFile(url, "C:\thing.jpg")
            wc.Dispose()

That would be great if it actually did anything. The file thing.jpg seems never to be created. So I put in a messagebox right after that code to give me a chance to see if the file was there on my hard-drive. And it wasn't. The picture shows fine in IE/Mozilla, and there are no credentials required to view it. I just can't seem to get my head round it. Any help would be greatly appreciated.

Regards
James
 
Back
Top