6

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

                        }
Andrii Kalytiiuk
  • 1,501
  • 14
  • 26
ALT
  • 63
  • 1
  • 6

1 Answers1

1

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

Community
  • 1
  • 1
Majid
  • 13,853
  • 15
  • 77
  • 113
  • i Try this but downloaded path file contain HTML tag and some related text which is not actual text of file to download. – ALT Jul 09 '13 at 19:44
  • @MaiHuNa Did it download file with extra texts? – Majid Jul 11 '13 at 09:57
  • @MaiHuNa It seems file that you want to download needs login first. test my code with another file that don't need login. – Majid Jul 12 '13 at 13:45
  • i need to download files after login its my requirement – ALT Jul 15 '13 at 08:44
  • i used this but not work client.Credentials = new System.Net.NetworkCredential("username", "password"); – ALT Jul 15 '13 at 08:45