|
-
Apr 2nd, 2004, 07:51 AM
#1
Thread Starter
Fanatic Member
Download from web [RESOLVED]
HI all,
I have a webpath say: www.webserver.com/getfile.asp
How to download the resulting htm file thru vb.net?
in vb6 i used to do the following:
VB Code:
Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Public Function DownloadFile(ByVal URL As String, ByVal LocalFilename As String) As Boolean
Dim lngRetVal As Long
lngRetVal = URLDownloadToFile(0, URL, LocalFilename, 0, 0)
If lngRetVal = 0 Then DownloadFile = True
End Function
pls guide
Last edited by pvbangera; Apr 2nd, 2004 at 10:21 AM.
-
Apr 2nd, 2004, 09:19 AM
#2
I wonder how many charact
VB Code:
Dim myClient As New System.Net.WebClient
myClient.DownloadFile("http://www.google.com","C:\mydump.txt")
Good enough?
-
Apr 2nd, 2004, 09:33 AM
#3
Thread Starter
Fanatic Member
I tried that. But it gives me following error:
'The underlying connection was closed: The remote name could not be resolved.'
If I copy and paste the same URL in IE then the page is opened without any error.
-
Apr 2nd, 2004, 09:42 AM
#4
I wonder how many charact
Well, I don't know exactly what you wanted out of the function, here's the same thing kind of with error-catching, and intretval will return 0 if the resource was not found, resulting in a false return from the function.
VB Code:
Public Function DownloadFile(ByVal URL As String, ByVal LocalFileName As String) As Boolean
Dim myClient As New System.Net.WebClient
Dim result As Boolean = False
Dim S As System.IO.FileStream
Dim myBuffer As Byte()
Try
myBuffer = myClient.DownloadData(URL)
S = New IO.FileStream(LocalFileName, IO.FileMode.OpenOrCreate)
S.Write(myBuffer, 0, myBuffer.Length)
S.Flush()
Catch
Finally
If Not S Is Nothing Then S.Close()
myClient.Dispose()
End Try
If Not myBuffer Is Nothing Then result = True
Return result
End Function
If that works for you, please append resolved to your message title.
Last edited by nemaroller; Apr 2nd, 2004 at 09:51 AM.
-
Apr 2nd, 2004, 10:21 AM
#5
Thread Starter
Fanatic Member
its working fine. thanx a lot. u r a darling
-
Apr 3rd, 2004, 04:38 AM
#6
Thread Starter
Fanatic Member
The stuff is working fine. But it takes lots of time to download.
Is there any other way out?
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
|