How to use URLDownloadToFile

  • Thread starter Thread starter oLiVieR CheNeSoN
  • Start date Start date
O

oLiVieR CheNeSoN

Hi,


I would like to use URLDownloadToFile in my C# application.

How do i declare this function ?

Do you have any example ?


THanks
Olivier
 
Hi Morten,


Thanks for your reply.

Another question , i would like to download from https and it doesnt work.


do you have some example or hints ?


Thanks
Olivier
Morten Wennevik said:
Hi Olivier,

Wouldn't WebClient.DownloadFile be easier?
 
oLiVieR said:
Hi Morten,


Thanks for your reply.

Another question , i would like to download from https and it doesnt
work.


do you have some example or hints ?

"Doesn't work" isn't a really helpful error description. What happens?
Do you receive a WebException? Can you post your code?

Cheers,
 
Hi,


This is the error i got

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Net.WebException: The underlying connection was closed: Could not
establish trust relationship with remote server.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
at System.Net.HttpWebRequest.GetResponse()
at System.Net.WebClient.DownloadFile(String address, String fileName)
at DOMHandler.L10N.SaveImgFile(HTMLDocumentClass myDoc, String
SaveFolder, String SRCRelative)
at DOMHandler.L10N.GetHTMLDoc(HTMLDocumentClass myDoc, String
strFileName, String strFullPath)
at eTravelBar.LocalisationBar.buttonSave_Click(Object sender, EventArgs
e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg,
IntPtr wparam, IntPtr lparam)


************** Loaded Assemblies **************
mscorlib
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/winnt/microsoft.net/framework/v1.1.4322/mscorlib.dll
----------------------------------------
eTravelBar
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase:
file:///c:/winnt/assembly/gac/etravelbar/1.0.0.0__8573eaf5f7626b79/etravelbar.dll
----------------------------------------
BandObjectLib
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase:
file:///c:/winnt/assembly/gac/bandobjectlib/1.0.0.0__4b827ebe229d539f/bandobjectlib.dll
----------------------------------------
System.Windows.Forms
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/winnt/assembly/gac/system.windows.forms/1.0.5000.0__b77a5c561934e089/system.windows.forms.dll
----------------------------------------
System
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/winnt/assembly/gac/system/1.0.5000.0__b77a5c561934e089/system.dll
----------------------------------------
System.Drawing
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/winnt/assembly/gac/system.drawing/1.0.5000.0__b03f5f7f11d50a3a/system.drawing.dll
----------------------------------------
Interop.SHDocVw
Assembly Version: 1.1.0.0
Win32 Version: 1.1.0.0
CodeBase:
file:///c:/winnt/assembly/gac/interop.shdocvw/1.1.0.0__4b827ebe229d539f/interop.shdocvw.dll
----------------------------------------
DOMHandler
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase:
file:///c:/winnt/assembly/gac/domhandler/1.0.0.0__8573eaf5f7626b79/domhandler.dll
----------------------------------------
Microsoft.mshtml
Assembly Version: 7.0.3300.0
Win32 Version: 7.0.3300.0
CodeBase:
file:///c:/winnt/assembly/gac/microsoft.mshtml/7.0.3300.0__b03f5f7f11d50a3a/microsoft.mshtml.dll
----------------------------------------
CustomMarshalers
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.573
CodeBase:
file:///c:/winnt/assembly/gac/custommarshalers/1.0.5000.0__b03f5f7f11d50a3a/custommarshalers.dll
----------------------------------------
System.Xml
Assembly Version: 1.0.5000.0
Win32 Version: 1.1.4322.2032
CodeBase:
file:///c:/winnt/assembly/gac/system.xml/1.0.5000.0__b77a5c561934e089/system.xml.dll
----------------------------------------

************** JIT Debugging **************
To enable just in time (JIT) debugging, the config file for this
application or machine (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.

For example:

<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>

When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the machine
rather than being handled by this dialog.
 
oLiVieR said:
Hi,


This is the error i got

See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Net.WebException: The underlying connection was closed: Could
not establish trust relationship with remote server.
at System.Net.HttpWebRequest.CheckFinalStatus()
at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult
asyncResult) at System.Net.HttpWebRequest.GetResponse()
at System.Net.WebClient.DownloadFile(String address, String
fileName) at DOMHandler.L10N.SaveImgFile(HTMLDocumentClass myDoc,
String SaveFolder, String SRCRelative)
at DOMHandler.L10N.GetHTMLDoc(HTMLDocumentClass myDoc, String
strFileName, String strFullPath)
at eTravelBar.LocalisationBar.buttonSave_Click(Object sender,
EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons
button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32
msg, IntPtr wparam, IntPtr lparam)
[...]

This typically happens when the server certificate is rejected by the
framework's default certificate policy. Have a look at
System.Net.ICertificatePolicy's documentation on MSDN.

Cheers,
 
Back
Top