在c#webbrowser控件中保存文件而不保存文件对话框



我正在使用C#代码实现从客户端站点自动下载文件的代码,而无需手动步骤。

我的要求是通过C#代码保存文件,方法是传递路径而不保存文件对话框。

这是在C#窗口WebBrowser控件中单击下载按钮时显示保存文件对话框的代码。

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

您可以使用这样的东西,它不会显示任何可供下载的对话框:

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

从这里

最新更新