473,320 Members | 1,810 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

WebClient.DownloadFileAsync

Hi Guys,

Really strange problem I am experiencing... I have setup a virtual
directory with Read Only permissions on an ISA/IIS server (SBS 2003). In
that virt. dir., I placed 1 file (setup.exe). I then use
WebClient.DownloadFileAsync (.NET 2.0 Pro.) and all downloads well including
progress bar indicator, bytes received, etc... Here is the problem:

When I replace the file (setup.exe), with a different, larger file, it
still downloads the old/original one. I guess ISA/IIS server must keep a
cache of it somewhere. I've searched the entire hard drive, but cannot find
it. Is there any way to circumvent this caching which is causing my problem?
I don't think it has anything to do with my code as I receive the file
properly. The only issue is that if I were to replace the same file, with a
newer version, it still downloads the old one...

Regards,

Giovanni
Mar 2 '06 #1
6 22003
Thus wrote Giovanni,
Hi Guys,

Really strange problem I am experiencing... I have setup a
virtual directory with Read Only permissions on an ISA/IIS server (SBS
2003). In that virt. dir., I placed 1 file (setup.exe). I then use
WebClient.DownloadFileAsync (.NET 2.0 Pro.) and all downloads well
including progress bar indicator, bytes received, etc... Here is the
problem:

When I replace the file (setup.exe), with a different, larger
file, it
still downloads the old/original one. I guess ISA/IIS server must
keep a
cache of it somewhere. I've searched the entire hard drive, but
cannot find
it. Is there any way to circumvent this caching which is causing my
problem?


You can control caching from the client side using WebClient.CachePolicy
property.

RequestCachePolicy policy = new RequestCachePolicy(RequestCacheLevel.Reload);
WebClient client = new WebClient();
client.CachePolicy = policy;

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 2 '06 #2
Hi Joerg,

Thank you for your answer. It worked as soon as I implemented your
solution. I do have one other small issue now. I need to download more than
one file at once; maybe 2-3. I have the DownloadFileAsync working properly
(it seems to), but when I try to start call the DownloadFileAsync method
again specifying another source and destination, it gives me the following
error:

WebClient does not support concurrent I/O operations.

System.NotSupportedException was caught
Message="WebClient does not support concurrent I/O operations."
Source="System"
StackTrace:
at System.Net.WebClient.ClearWebClientState()
at System.Net.WebClient.DownloadFileAsync(Uri address, String
fileName, Object userToken)
at System.Net.WebClient.DownloadFileAsync(Uri address, String fileName)
at WindowsApplication1.Form1.btnDownload_Click(Object sender,
EventArgs e) in C:\Documents and Settings\test\My Documents\Visual Studio
2005\Projects\WindowsApplication1\WindowsApplicati on1\Form1.vb:line 43
Any ideas why? Thanks for all your help on this. I really appreciate it.
Giovanni

"Joerg Jooss" wrote:
Thus wrote Giovanni,
Hi Guys,

Really strange problem I am experiencing... I have setup a
virtual directory with Read Only permissions on an ISA/IIS server (SBS
2003). In that virt. dir., I placed 1 file (setup.exe). I then use
WebClient.DownloadFileAsync (.NET 2.0 Pro.) and all downloads well
including progress bar indicator, bytes received, etc... Here is the
problem:

When I replace the file (setup.exe), with a different, larger
file, it
still downloads the old/original one. I guess ISA/IIS server must
keep a
cache of it somewhere. I've searched the entire hard drive, but
cannot find
it. Is there any way to circumvent this caching which is causing my
problem?


You can control caching from the client side using WebClient.CachePolicy
property.

RequestCachePolicy policy = new RequestCachePolicy(RequestCacheLevel.Reload);
WebClient client = new WebClient();
client.CachePolicy = policy;

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Mar 3 '06 #3
Thus wrote Giovanni,
Hi Joerg,

Thank you for your answer. It worked as soon as I implemented
your solution. I do have one other small issue now. I need to
download more than one file at once; maybe 2-3. I have the
DownloadFileAsync working properly (it seems to), but when I try to
start call the DownloadFileAsync method again specifying another
source and destination, it gives me the following error:

WebClient does not support concurrent I/O operations.

System.NotSupportedException was caught
Message="WebClient does not support concurrent I/O operations."
Source="System"
StackTrace:
at System.Net.WebClient.ClearWebClientState()
at System.Net.WebClient.DownloadFileAsync(Uri address, String
fileName, Object userToken)
at System.Net.WebClient.DownloadFileAsync(Uri address, String
fileName)
at WindowsApplication1.Form1.btnDownload_Click(Object sender,
EventArgs e) in C:\Documents and Settings\test\My Documents\Visual
Studio
2005\Projects\WindowsApplication1\WindowsApplicati on1\Form1.vb:line 43

Any ideas why? Thanks for all your help on this. I really appreciate
it.


I don't think you can use a single WebClient instance to execute several
HTTP requests at the same time. Try to create a WebClient instance per request,
that should work just fine.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 3 '06 #4
Hi Joerg,

Thank you once again for your help. I've declared a second object and
also initiated the download at the same time as the first. All worked well.
What I'd like to do is now make this approcah more generalized, i.e., build a
class, add a file to download and begin the download progress asynchronously,
while updating a (new) progress bar for each file being downloaded. The
class part is what fumbles me a little. Any ideas on whether I should use
threads or does the DownloadFileAsync method automatically use a thread from
the existing thread pool provided. Should I provide callbacks
(IAsyncResult), or just raise events from my class for the
DownloadFileComplete or DownloadProgressChange events. Do Delegates fit into
this picture?

Thank you for your input.

Regards,

Giovanni

"Joerg Jooss" wrote:
Thus wrote Giovanni,
Hi Joerg,

Thank you for your answer. It worked as soon as I implemented
your solution. I do have one other small issue now. I need to
download more than one file at once; maybe 2-3. I have the
DownloadFileAsync working properly (it seems to), but when I try to
start call the DownloadFileAsync method again specifying another
source and destination, it gives me the following error:

WebClient does not support concurrent I/O operations.

System.NotSupportedException was caught
Message="WebClient does not support concurrent I/O operations."
Source="System"
StackTrace:
at System.Net.WebClient.ClearWebClientState()
at System.Net.WebClient.DownloadFileAsync(Uri address, String
fileName, Object userToken)
at System.Net.WebClient.DownloadFileAsync(Uri address, String
fileName)
at WindowsApplication1.Form1.btnDownload_Click(Object sender,
EventArgs e) in C:\Documents and Settings\test\My Documents\Visual
Studio
2005\Projects\WindowsApplication1\WindowsApplicati on1\Form1.vb:line 43

Any ideas why? Thanks for all your help on this. I really appreciate
it.


I don't think you can use a single WebClient instance to execute several
HTTP requests at the same time. Try to create a WebClient instance per request,
that should work just fine.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de

Mar 3 '06 #5
Thus wrote Giovanni,
Hi Joerg,

Thank you once again for your help. I've declared a second
object and also initiated the download at the same time as the first.
All worked well. What I'd like to do is now make this approcah more
generalized, i.e., build a class, add a file to download and begin the
download progress asynchronously, while updating a (new) progress bar
for each file being downloaded. The class part is what fumbles me a
little. Any ideas on whether I should use threads or does the
DownloadFileAsync method automatically use a thread from the existing
thread pool provided. Should I provide callbacks (IAsyncResult), or
just raise events from my class for the DownloadFileComplete or
DownloadProgressChange events. Do Delegates fit into this picture?


DownloadFileAsync will execute the callback on a threadpool thread.

The question is what kind of programming model you want to offer to your
component's users (i.e. developers). The best approach is certainly to offer
events. Since the actual number of event sources varies in your case (it's
bound to the number of active WebClients), you'll need some way of mapping
the underyling WebClient event to your own event. From a programming perspective,
it's probably easier for you if you just add a delegate to your own Download()
method, and call the delegate for each progress bar step.

Cheers,
--
Joerg Jooss
ne********@joergjooss.de
Mar 4 '06 #6
Hi Joerg,

The class I'd like to build would be instanced several times in a
WinForms application. I'd specify a separate progressbar for every new
instance of the class and begin the download. I am having a problem
conceptualizing the way my class is to be built and the way each individual
instance is to communicate with a specific progress bar and raise the events.
It's blurry. I have searched the internet for examples of the WebClient
class being used in a custom built class that downloads multiple files but
nothing so far. Would you know of any (VB.NET prefferably)? This is what I
have so far. Is my class on the right track? Just want to know if they way
I am raising events to a WindowsForms client from a .dll is the correct way
and the way I cancel the operation is also OK. Thanks again for your help.
'Declared in another .VB file.

Public Delegate Sub DownloadCompleteHandler(ByVal sender As Object, _
ByVal e As DownloadDataCompletedEventArgs)

Public Delegate Sub DownloadProgressChangeHandler(ByVal sender As Object,_
ByVal e As DownloadProgressChangedEventArgs)
Public Class AutoUpdate
Private _WebClient As WebClient
Private _DownloadURL As String

Public Event CompleteCallback As DownloadCompleteHandler
Public Event ProgressCallback As DownloadProgressChangeHandler

Public Sub New()
'Base constructor.
End Sub

Public Sub New(ByVal downloadURL As String, ByVal destination As
String)
_WebClient = New WebClient
AddHandler _WebClient.DownloadFileCompleted, _
AddressOf DownloadCompleteHandler

AddHandler _WebClient.DownloadProgressChanged, _
AddressOf DownloadProgressChangedHandler

_WebClient.DownloadFileAsync(New Uri(downloadURL), destination)
End Sub

Public Property DownloadURL() As String
Get
Return Me._DownloadURL
End Get
Set(ByVal value As String)
Me._DownloadURL = value
End Set
End Property

Public Sub DownloadCompleteHandler(ByVal sender As Object, _
ByVal e As ComponentModel.AsyncCompletedEventArgs)

RaiseEvent CompleteCallback(sender, e)

End Sub

Public Sub DownloadProgressChangedHandler(ByVal sender As Object, _
ByVal e As Net.DownloadProgressChangedEventArgs)

RaiseEvent ProgressCallback(sender, e)
End Sub

Public Sub Cancel()
_WebClient.CancelAsync()
End Sub
End Class
Mar 5 '06 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: ptass | last post by:
Hi I've installed win2k3 sp1 on a machine where an openRead on any given file was previously working. After installation, I get a webException as follows... ..message "An exception occurred...
3
by: Ram Baruch | last post by:
Hi, I'm trying to use WebClient class to upload data. In order to upload it, I need to use my username and password. Does somebody know how can I set it in the WebClient class? Regards, Ram.
2
by: xzzy | last post by:
I have .net 1.1 c# . . . . . using System.Net only lists sockets what do I need to do to be able to do: using System.Net.WebClient;
6
by: A.M-SG | last post by:
Hi, I have an aspx page at the web server that provides PDF documents for smart client applications. Here is the code in aspx page that defines content type: Response.ContentType =...
1
by: vin.dor | last post by:
Dear All, I am using WebClient in my Visual Studio .Net 2003 project to download an image from the Internet. The following is my function: C# Code: public static bool downloadFile(string...
1
by: Mad Scientist Jr | last post by:
For some reason I can't get a WebClient to access an outside URL from behind our firewall. The code works when it runs outside the firewall. I turned on windows authentication in the web.config...
1
by: Mike | last post by:
I am using PowerShell to download an XML file into a string using the DownloadString(URI) method of System.Net.WebClient object. Sample commands below: $Result = $Null; $WebClient = new-object...
2
by: MichaelSchoeler | last post by:
Hi, I'm having problems with the WebClient class regarding UTF-8 encoded data. When I access a specific webservice directly I can see the data arrives in corretly formatted UTF-8. But when I...
6
by: sajjadlove | last post by:
Hi there i use from following code for download a file from ftp server but it doesn't work...... what's that problem ?!...... //FTP Class public event...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.