Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
                            }

                        }
like image 617
ALT Avatar asked Nov 02 '22 18:11

ALT


1 Answers

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

like image 125
Majid Avatar answered Nov 15 '22 07:11

Majid