使用webbrowser下载文件 [英] Download file using webbrowser

查看:79
本文介绍了使用webbrowser下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

\WebBrowser Control我设法登录网站,但在导航到报告URL时,显示我想跳过的保存下载对话框,让它将report.csv下载到指定位置。



WebClient为了跳过保存文件对话框我尝试了DownloadFile()方法,它下载登录页面而不是实际报告。我还尝试在下载文件之前通过WebClient登录,但没有运气。仍然似乎下载登录页面。



我也通过将WebBrowser Control中的cookie传递给WebClient来尝试组合



我们将非常感谢您的帮助。

PS我正在浏览的网站是在asp.net



我尝试了什么:



我也通过将Cookie从WebBrowser Control传递到WebClient来尝试组合

\WebBrowser Control I managed to log into the website but while navigating to report URL it display "Save Download Dialog" which I want to skip and let it download the report.csv to a specified location.

WebClient In order to skip Save file Dialog I tried DownloadFile() method and it downloads login page instead of the actual report. I also tried to login through WebClient before downloading the file and again no luck. Still it seems to download login page.

I also tried in the combination by passing cookies from WebBrowser Control to WebClient

Your help will be greatly appreciated.
P.S. the website i'm navigating is in asp.net

What I have tried:

I also tried in the combination by passing cookies from WebBrowser Control to WebClient

推荐答案

我已经解决了这个问题,以防有人在寻找解决方案:



使用打开/保存对话框下载文件 [ ^ ]
I have solved this problem in case somebody looking for solution:

Download of file with open/save dialog box[^]


//尝试此代码,它会弹出保存按钮,弹出后也会选择//位置它将关闭弹出窗口。



按下下载按钮后插入此代码。弹出窗口打开后会触发。



线程th =新线程(()=>

{

System.Threading.Thread.Sleep(10000);

SendKeys.SendWait({Tab});

SendKeys.SendWait({Tab}) ;

SendKeys.SendWait({Tab});

SendKeys.SendWait({Enter});

System.Threading .Tread.Sleep(5000);

SendKeys.SendWait({Tab});

SendKeys.SendWait({Tab});

SendKeys.SendWait({Tab});

SendKeys.SendWait({Enter});

});

th.SetApartmentState(ApartmentState.MTA);

th.Start();
//try this code, it will press save button from popup and after it will also select //location and it will close popup.

insert this code after download button pressed. it will fire once your popup opened.

Thread th = new Thread(() =>
{
System.Threading.Thread.Sleep(10000);
SendKeys.SendWait("{Tab}");
SendKeys.SendWait("{Tab}");
SendKeys.SendWait("{Tab}");
SendKeys.SendWait("{Enter}");
System.Threading.Thread.Sleep(5000);
SendKeys.SendWait("{Tab}");
SendKeys.SendWait("{Tab}");
SendKeys.SendWait("{Tab}");
SendKeys.SendWait("{Enter}");
});
th.SetApartmentState(ApartmentState.MTA);
th.Start();


这篇关于使用webbrowser下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆