/// <summary>
/// The URLMON library contains this function, URLDownloadToFile, which is a way
/// to download files without user prompts. The ExecWB( _SAVEAS ) function always
/// prompts the user, even if _DONTPROMPTUSER parameter is specified, for "internet
/// security reasons". This function gets around those reasons.
/// </summary>
/// <param name="pCaller">Pointer to caller object (AX).</param>
/// <param name="szURL">String of the URL.</param>
/// <param name="szFileName">String of the destination filename/path.</param>
/// <param name="dwReserved">[reserved].</param>
/// <param name="lpfnCB">A callback function to monitor progress or abort.</param>
/// <returns>0 for okay.</returns>
[DllImport("urlmon.dll", CharSet=CharSet.Auto, SetLastError=true)]
static extern Int32 URLDownloadToFile(
[MarshalAs(UnmanagedType.IUnknown)] object pCaller,
[MarshalAs(UnmanagedType.LPWStr)] string szURL,
[MarshalAs(UnmanagedType.LPWStr)] string szFileName,
Int32 dwReserved,
IntPtr lpfnCB);
// This version maps HRESULT to exception:
[DllImport("urlmon.dll", CharSet=CharSet.Auto, PreserveSig=false)]
private static extern void URLDownloadToFile(
[MarshalAs(UnmanagedType.IUnknown)] object pCaller,
[MarshalAs(UnmanagedType.LPTStr)] string szURL,
[MarshalAs(UnmanagedType.LPTStr)] string szFileName,
Int32 dwReserved,
IntPtr lpfnCB);
Declare Function URLDownloadToFile Lib "urlmon.dll" (TODO) As TODO
None.
This function does not prompt user for file location, as does ExecWB (even when you specify DONTPROMPT), and it does not return until file transfer finishes or fails.
http://www.pinvoke.net/default.aspx/urlmon/URLDownloadToFile%20.html
Please add some!
int response = URLDownloadToFile( null, urlStr, fileToStoreStr, 0, IntPtr.Zero );
// For the second version:
URLDownloadToFile(IE as SHDocVw.IWebBrowser2, urlStr, fileToStoreStr, 0, IntPtr.Zero );
Do you know one? Please contribute it!