save file without save file dialog in c# webbrowser control
Asked Answered
C

1

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

                        }
Chromate answered 9/7, 2013 at 8:7 Comment(2)
Please be more careful about formatting next time.Peregrinate
This has been solved here: #3539374Ewe
G
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

Godden answered 9/7, 2013 at 8:39 Comment(5)
i Try this but downloaded path file contain HTML tag and some related text which is not actual text of file to download.Chromate
@MaiHuNa Did it download file with extra texts?Godden
@MaiHuNa It seems file that you want to download needs login first. test my code with another file that don't need login.Godden
i need to download files after login its my requirementChromate
i used this but not work client.Credentials = new System.Net.NetworkCredential("username", "password");Chromate

© 2022 - 2024 — McMap. All rights reserved.