473,785 Members | 2,607 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebClient.Downl oadFileAsync

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.Downl oadFileAsync (.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 22105
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.Downl oadFileAsync (.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.Cache Policy
property.

RequestCachePol icy policy = new RequestCachePol icy(RequestCach eLevel.Reload);
WebClient client = new WebClient();
client.CachePol icy = policy;

Cheers,
--
Joerg Jooss
ne********@joer gjooss.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 DownloadFileAsy nc working properly
(it seems to), but when I try to start call the DownloadFileAsy nc method
again specifying another source and destination, it gives me the following
error:

WebClient does not support concurrent I/O operations.

System.NotSuppo rtedException was caught
Message="WebCli ent does not support concurrent I/O operations."
Source="System"
StackTrace:
at System.Net.WebC lient.ClearWebC lientState()
at System.Net.WebC lient.DownloadF ileAsync(Uri address, String
fileName, Object userToken)
at System.Net.WebC lient.DownloadF ileAsync(Uri address, String fileName)
at WindowsApplicat ion1.Form1.btnD ownload_Click(O bject sender,
EventArgs e) in C:\Documents and Settings\test\M y Documents\Visua l Studio
2005\Projects\W indowsApplicati on1\WindowsAppl ication1\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.Downl oadFileAsync (.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.Cache Policy
property.

RequestCachePol icy policy = new RequestCachePol icy(RequestCach eLevel.Reload);
WebClient client = new WebClient();
client.CachePol icy = policy;

Cheers,
--
Joerg Jooss
ne********@joer gjooss.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
DownloadFileAsy nc working properly (it seems to), but when I try to
start call the DownloadFileAsy nc method again specifying another
source and destination, it gives me the following error:

WebClient does not support concurrent I/O operations.

System.NotSuppo rtedException was caught
Message="WebCli ent does not support concurrent I/O operations."
Source="System"
StackTrace:
at System.Net.WebC lient.ClearWebC lientState()
at System.Net.WebC lient.DownloadF ileAsync(Uri address, String
fileName, Object userToken)
at System.Net.WebC lient.DownloadF ileAsync(Uri address, String
fileName)
at WindowsApplicat ion1.Form1.btnD ownload_Click(O bject sender,
EventArgs e) in C:\Documents and Settings\test\M y Documents\Visua l
Studio
2005\Projects\W indowsApplicati on1\WindowsAppl ication1\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********@joer gjooss.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 DownloadFileAsy nc 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
DownloadFileCom plete or DownloadProgres sChange 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
DownloadFileAsy nc working properly (it seems to), but when I try to
start call the DownloadFileAsy nc method again specifying another
source and destination, it gives me the following error:

WebClient does not support concurrent I/O operations.

System.NotSuppo rtedException was caught
Message="WebCli ent does not support concurrent I/O operations."
Source="System"
StackTrace:
at System.Net.WebC lient.ClearWebC lientState()
at System.Net.WebC lient.DownloadF ileAsync(Uri address, String
fileName, Object userToken)
at System.Net.WebC lient.DownloadF ileAsync(Uri address, String
fileName)
at WindowsApplicat ion1.Form1.btnD ownload_Click(O bject sender,
EventArgs e) in C:\Documents and Settings\test\M y Documents\Visua l
Studio
2005\Projects\W indowsApplicati on1\WindowsAppl ication1\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********@joer gjooss.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
DownloadFileAsy nc 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 DownloadFileCom plete or
DownloadProgres sChange events. Do Delegates fit into this picture?


DownloadFileAsy nc 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********@joer gjooss.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 DownloadComplet eHandler(ByVal sender As Object, _
ByVal e As DownloadDataCom pletedEventArgs )

Public Delegate Sub DownloadProgres sChangeHandler( ByVal sender As Object,_
ByVal e As DownloadProgres sChangedEventAr gs)
Public Class AutoUpdate
Private _WebClient As WebClient
Private _DownloadURL As String

Public Event CompleteCallbac k As DownloadComplet eHandler
Public Event ProgressCallbac k As DownloadProgres sChangeHandler

Public Sub New()
'Base constructor.
End Sub

Public Sub New(ByVal downloadURL As String, ByVal destination As
String)
_WebClient = New WebClient
AddHandler _WebClient.Down loadFileComplet ed, _
AddressOf DownloadComplet eHandler

AddHandler _WebClient.Down loadProgressCha nged, _
AddressOf DownloadProgres sChangedHandler

_WebClient.Down loadFileAsync(N ew 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 DownloadComplet eHandler(ByVal sender As Object, _
ByVal e As ComponentModel. AsyncCompletedE ventArgs)

RaiseEvent CompleteCallbac k(sender, e)

End Sub

Public Sub DownloadProgres sChangedHandler (ByVal sender As Object, _
ByVal e As Net.DownloadPro gressChangedEve ntArgs)

RaiseEvent ProgressCallbac k(sender, e)
End Sub

Public Sub Cancel()
_WebClient.Canc elAsync()
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
942
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 during a webclient request" .._Hresult = "-2146233079" .._COMPlusExceptionCode ="-532459699" Sorry I don't have the whole error, but this seems to be the only pertinent
3
67671
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
5369
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
13304
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 = "application/octet-stream"; Response.AppendHeader("Content-Disposition", "attachment;filename=" + fileID.ToString() + ".pdf");
1
6293
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 URL, ref string fileName) { bool result = true;
1
6496
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 <authentication mode="Windows" /> and set up IIS to not allow anonymous access. My browser is set up to auto detect the proxy server, so IE/Firefox can access outside pages, so I added code to auto-detect the proxy server.
1
12504
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 System.Net.WebClient; $WebClient.Encoding = ::Default; $WebClient.Proxy = ::DefaultWebProxy; $WebClient.Proxy.Credentials = ::DefaultCredentials;
2
10175
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 try to pull data from the same webservice url through the WebClient class I get partly garbled UTF-8 data in return. Only some UTF-8 chars (double byte pairs) seems to be corrupted. // Does not work WebClient wc = new WebClient(); string...
6
11289
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 DownloadProgressChangedEventHandler DownloadProgressChanged; public event AsyncCompletedEventHandler DownloadFileCompleted; public void Download(string fileName,string savePath) {
0
9645
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9481
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10341
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10095
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9954
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5383
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5513
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2881
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.