简体   繁体   中英

save file without save file dialog in c# webbrowser control

I am implementing code to automatic download files from client site without manual step using C# code.

My requirement is to save the files through C# code by passing path without save file dialog.

This is code to show the Save file dialog when click on Download button in C# window WebBrowser control .

 foreach (HtmlElement row in webBrowser1.Document.Window.Frames["View_Frame"].Document.GetElementsByTagName("input"))
                        {
                            if (row.Name == "DOWNLOADALL")
                            {
                                row.InvokeMember("click");
                                tbState.Text = "4";
                                break;
                            }

                        }

You can use something like this that would not show any dialog for download:

WebClient client = new WebClient();
foreach (HtmlElement row in webBrowser1.Document.Window.Frames["View_Frame"].Document.GetElementsByTagName("input"))
  {
    if (row.Name == "DOWNLOADALL")
      {
        row.InvokeMember("click");
        tbState.Text = "4";
        client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
        client.DownloadFile(URL, path);//I don't know where is your URL and path!
        break;
      }

 }

from here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM