URLDownloadToFile Doesn't work in VB.NET?

  • Thread starter Thread starter Steeden Macdonalds via .NET 247
  • Start date Start date
S

Steeden Macdonalds via .NET 247

Does anyone knows why the function URLDownloadToFile doesn't work in .NET?
I can use this function and it seems to be working fine in VB6 but when I use it in VB.NET, I am getting a really long error code.

I can't use WebClient.DownloadFile as this does not suit my purpose (i've tried it and that didn't work either)

Any ideas/help appreciated?

Samples codes below:

Private 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

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim lErrcode As Long
Dim sFullImageURL As String = "http://itg.unl.edu/new_itg/Resources/ExcelGraphs.pdf"
Dim sLocalFileName As String = "C:\Temp1\Test.pdf"

lErrcode = URLDownloadToFile(0, sFullImageURL, sLocalFileName, 0, 0)
If lErrcode <> 0 Then
Call Err.Raise(123, "Error while creating local copy of PDF document. Error Code = " & lErrcode)
End If
 
Steeden said:
Does anyone knows why the function URLDownloadToFile doesn't work in
.NET? I can use this function and it seems to be working fine in VB6
but when I use it in VB.NET, I am getting a really long error code.

I can't use WebClient.DownloadFile as this does not suit my purpose
(i've tried it and that didn't work either)
[...]

What's wrong with WebClient? From your code sample, I can't see
anything special about your purpose...


Cheers,
 
Back
Top