0
我正在用windows.Forms.WebBrowser c#下載文件,運行InvokeScript之後,並獲取我的文件我使用Application.DoEvents向前移動到我的下一個文件,但下載對話框保持打開狀態,我被卡在Application.DoEvents上,無法做任何事情。WebBrowser關閉文件下載對話框
如何取消或關閉此下載對話框?
我的代碼:
HtmlElement head = webBrowser.Document.GetElementById("btnExcelExport");
HtmlElement scriptEl = webBrowser.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)scriptEl.DomElement;
element.text = "function DownloadFile() {$('#btnExcelExport').click()}";
head.AppendChild(scriptEl);
webBrowser.Document.InvokeScript("DownloadFile");
HtmlElementCollection iFrames = webBrowser.Document.GetElementsByTagName("iframe");
for (int i = 0; i < iFrames.Count; i++)
{
string src = iFrames[i].GetAttribute("src");
if (src.Contains("Export"))
{
txt_url.Text = "https://test.com" + src;
string cooki = webBrowser.Document.Cookie;
int response = URLDownloadToFile(0, "https://test.com" + src, @"C:\temp\Test.txt", 0, 0);
}
}
Application.DoEvents();
//....got to next file