Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cannot download file using webclient

Status
Not open for further replies.

aspro

Programmer
Jan 22, 2003
69
AU
Hi
I wanted to be able to download a file from a web server using the downloadfile method. I have successfully managed to download the file (which is a small text file), however the text file is empty when it should have text in it. My download code is as follows

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim sFile As String
sFile = "enquiries.txt"
Dim destination As String
destination = "F:\bushire\"
Dim sRemoteUrl As String
sRemoteUrl = " + sFile
'download file
GetPackage(sFile, destination, sRemoteUrl)
End Sub

Public Sub GetPackage(ByVal sFile As String, ByVal destination As String, ByVal sRemoteUrl As String)
'Downloads the enquiries file and stores it in the destination address with the same name
Dim wc As New Net.WebClient
Try
wc.DownloadFile(sRemoteUrl, sFile)

MsgBox("download successful")
Catch
MsgBox("Unable to download file " + sRemoteUrl)
End Try
End Sub


Any help would be great,
Thanks in advance,
aspro
 
I tried this and it works.

There's an error in the line:
Code:
sRemoteUrl = "[URL unfurl="true"]http://www.dions.com.au/bushire/";[/URL] + sFile

It should read:
Code:
sRemoteUrl = "[URL unfurl="true"]http://www.dions.com.au/bushire/"[/URL] + sFile
- no semi-colon

I've also noticed that you declare but don't use the variable 'destination'. The way it's written above, the file is downloaded to the application's directory (the bin folder during debug).

-Stephen Paszt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top