|
-
Sep 21st, 2006, 10:39 AM
#1
Thread Starter
New Member
How do you download a file?
Right I apologize if this has been asked before, but I need to find an answer as I start my major college project in a few weeks.
Right, I am planning on making a program that will let the user search through a database then download files that are related to their search. I need to be able to do two things.
1) Acces a file and download it. Whilst it downloads I need it to report the progress to the progress bar.
2) Depending on where I keep the database (online or locally) I will need the program to automaticaly download new database updates. This one is optional because like I said it depends on if I put the database online or bundle it with the program.
I appreciate any help or links to tutorials 
Many thanks in advance, Jake.
-
Sep 21st, 2006, 11:21 AM
#2
Fanatic Member
Re: How do you download a file?
To begin with, you need to read about HttpWebRequest and FtpWebRequest (in .NET 2.0 only).
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Sep 21st, 2006, 11:56 AM
#3
Thread Starter
New Member
Re: How do you download a file?
OK, I have found methods of downloading using those, I got the HTTpWebRequest one working, but what I am struggling with now is how to implement a progress ba with that.
Any suggestions?
-
Sep 21st, 2006, 12:27 PM
#4
Fanatic Member
Re: How do you download a file?
Try this, I think I found it at in an article at http://www.c-sharpcorner.com but not sure about the exact link (Thanks to the original author).
VB Code:
Private Sub DownloadFile(byval filetoDownload)
Dim req As HttpWebRequest
Dim wc As WebClient
Dim client As WebClient
Dim data As Stream
Dim reader As StreamReader
Dim wProxy As WebProxy
Dim str As String = ""
Try
client = New WebClient
Dim URL As String = filetoDownload ' e.g http://www.abc.com/file.txt"
data = client.OpenRead(URL)
reader = New StreamReader(data)
dim allData as String
allData = reader.ReadToEnd())
' add necessary code to write this string to a file
Catch ex As Exception
MessageBox.Show(ex.ToString())
End Try
End Sub
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Sep 21st, 2006, 01:01 PM
#5
Addicted Member
Re: How do you download a file?
This is what I use.
WebAddress = "http://www.abc.com/file.txt"
VB Code:
Private Function DownloadFile(ByVal WebAddress As String) As String
Dim webfile As New WebClient
Dim URL As String = String.Empty
Try
strDoc = WebAddress.Substring(WebAddress.LastIndexOf("/"c) + 1)
If File.Exists(strDoc) = False Then
URL = WebAddress.Trim
webfile.DownloadFile(URL, strDoc)
End If
DownloadFile = ""
Catch ex As Exception
DownloadFile = ex.Message
Finally
webfile.Dispose()
End Try
End Function
-
Sep 22nd, 2006, 12:35 AM
#6
Fanatic Member
Re: How do you download a file?
Yep, Zombie_man23's solution is the right one if you're using VB.NET 2005. Mine was written for VB.NET 2003.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Oct 5th, 2007, 10:53 AM
#7
Re: How do you download a file?
If you are using 2005 I think you can use this putting in the information as you need it:
vb Code:
My.Computer.Network.DownloadFile("address", "destination", "userName Here", "Password Here")
Although there must be a way of doing it with the WebClient as well. Have you checked out the webClient documentation on MSDN to find the answer??
-
Oct 5th, 2007, 11:08 AM
#8
Re: How do you download a file?
look at my signature for example code on download a file with progress bar
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|