downLoadFile Issue

I

IntraRELY

I have a loop that loops through this sub. However, I recieve an
WebException error in my try statement. "An exception occurred during a
WebClient request." This message doesnt happen when I am only looping
throught the sub once, however when I process multiple records, I recieve
this error for every record after the first one.

And the images that is downloaded does show up for all records processed. So
everything works there is just an error, that says to the contrary.

TIA,

Steve Wofford


' Create a new WebClient instance.
Dim myWebClient As New System.Net.WebClient
' Sets the default image directory
Dim checksSignatureUri As String = "http://68.106.74.63/rateQuest/images/"
' Sets the imagename used for both download and local file access
Dim checksSignatureFileName As String = "checksSignature.jpg"
' Sets download resource
Dim checksSignatureResource As String = checksSignatureUri +
checksSignatureFileName
' Sets the local resource for local app to access the downloaded file
Dim checksSignatureLocalFile As String = "C:\" + checksSignatureFileName
Try
' Downloads the file
myWebClient.DownloadFile(checksSignatureResource, checksSignatureLocalFile)
Catch ex As System.Net.WebException
MsgBox("Unexpected Error occurred with Check Signature Image from URL: " &
ex.Message.ToString())
' INSERT AN EXIT APPICATIION METHOD TO CLOST THE APP.
End Try
' Imports checksSignature.jpg 150px X 60px
Dim checksSignature As New Bitmap(checksSignatureLocalFile)
xPos = leftMargin + 450
yPos = topMargin + 120
ev.Graphics.DrawImage(checksSignature, xPos, yPos)
 
G

Gary Chang

Hi

Thanks for using Microsoft MSDN Managed Newsgroup.

Currently I am looking for somebody who could help you on it. We will reply
here with more information as soon as possible.
If you have any more concerns on it, please feel free to post here.


Thanks!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
P

Peter Huang

Hi Steve,

First of all, I would like to confirm my understanding of your issue.
From your description, I understand that you wants to downloadfile using
WebClient and display them
in a loop and you get the "An exception occurred during a WebClient
request."
Have I fully understood you? If there is anything I misunderstood, please
feel free to let me know.

Based on my test, I can not reproduce the problem. Here is my test code,
you may have a try and let me know the result.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim str(4) As String
Dim i As Integer
'Put four file "Bluehills.jpg", "Sunset.jpg", "Waterlilies.jpg" and
"Winter.jpg" in the C:\Inetpub\wwwroot
str(0) = "Bluehills.jpg"
str(1) = "Sunset.jpg"
str(2) = "Waterlilies.jpg"
str(3) = "Winter.jpg"
For i = 0 To 3
Dim myWebClient As New System.Net.WebClient
'myWebClient.Credentials = CredentialCache.DefaultCredentials
' Sets the default image directory
Dim checksSignatureUri As String = "http://localhost/"
' Sets the imagename used for both download and local file
access
Dim checksSignatureFileName As String = str(i)
' Sets download resource
Dim checksSignatureResource As String = checksSignatureUri +
checksSignatureFileName
' Sets the local resource for local app to access the
downloaded file
Dim checksSignatureLocalFile As String = "c:\" +
checksSignatureFileName
Try
' Downloads the file
myWebClient.DownloadFile(checksSignatureResource,
checksSignatureLocalFile)
Catch ex As System.Net.WebException
Console.WriteLine("Unexpected Error occurred with Check
Signature Image from URL: " & ex.Message.ToString())
' INSERT AN EXIT APPICATIION METHOD TO CLOST THE APP.
End Try
' Imports checksSignature.jpg 150px X 60px
Dim checksSignature As New Bitmap(checksSignatureLocalFile)
'Use the CreateGraphics method to create a Graphics object.
Dim formGraphics As Graphics
formGraphics = Me.CreateGraphics
'Draw a rectangle on the form.
formGraphics.DrawImage(checksSignature, 0, 0)
System.Threading.Thread.Sleep(1000)
Next
End Sub

Please Apply My Suggestion Above And Let Me Know If It Helps Resolve Your
Problem.
However, if the problem still persists, you may also simplifie your code as
long as it can reproduce the problem as post here.

Best regards,

Perter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I

IntraRELY

Thanks Peter,

I believe I solved the problem, your example provided a differant file name
per loop iteration. However mine stayed the same, and I believe it was due
to the fact that the download was trying to overwrite a file that already
existed, and causing an error. As soon as I put a
If counter = 0 The
DownloadFile
EndIf
Do rest of loop....

That is all I really changed, but the error didnt have anything to say about
a file protection error, but is working now and wanted to thank you.

Steve Wofford
www.IntraRELY.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top