简体   繁体   English

在C#Webbrowser控件中保存文件而不保存文件对话框

[英]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. 我正在实现代码以自动从客户端站点下载文件,而无需使用C#代码进行手动操作。

My requirement is to save the files through C# code by passing path without save file dialog. 我的要求是通过C#代码通过传递路径而不保存文件对话框来保存文件。

This is code to show the Save file dialog when click on Download button in C# window WebBrowser control . 这是在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;
                            }

                        }

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 这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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