Reference link Https://stackoverflow.com/questions/6773866/download-file-and-automatically-save-it-to-folder
Public classMywebbrowser:webbrowser {/// <summary> ///The URLMON library contains this function, Urldownloadtofile, which is a -///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= "Callerpointer" >Pointer to Caller object (AX).</param> /// <param name= "url" >String of the URL.</param> /// <param name= "Filepathwithname" >String of the destination Filename/path.</param> /// <param name= "reserved" >[reserved].</param> /// <param name= "CallBack" >A callback function to monitor progress or abort.</param> /// <returns>0 for okay.</returns> ///Source:http://www.pinvoke.net/default.aspx/urlmon/URLDownloadToFile%20.html[DllImport ("Urlmon.dll", CharSet = CharSet.Auto, SetLastError =true)] Static externInt32 Urldownloadtofile ([MarshalAs (Unmanagedtype.iunknown)]ObjectCallerpointer, [MarshalAs (UNMANAGEDTYPE.LPWSTR)]stringURL, [MarshalAs (UNMANAGEDTYPE.LPWSTR)]stringfilepathwithname, Int32 reserved, IntPtr callBack); /// <summary> ///Download a file from the webpage and save it to the destination without promting the user/// </summary> /// <param name= "url" >The URL with the file</param> /// <param name= "Destinationfullpathwithname" >The Absolut full path with the filename as destination</param> /// <returns></returns> PublicFileInfo DownloadFile (stringUrlstringdestinationfullpathwithname) {Urldownloadtofile (NULL, URL, Destinationfullpathwithname,0, IntPtr.Zero); return NewFileInfo (destinationfullpathwithname); } }
Then use this Mywebbrowser control instead of the. NET-brought WebBrowser.
Use when downloading files
Webbrowser1.downloadfile (DownloadURL,"test.csv");
C # WebBrowser control download file do not play Download prompt box method