C # WebBrowser control download file do not play Download prompt box method

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.