[英]Download file without save dialog
In VB.NET I need to download a file from the web but without the save dialog box appearing. 在VB.NET中,我需要从Web下载文件,但没有出现“保存”对话框。 I am using a .net web browser control.
我正在使用.net Web浏览器控件。
The catch here is I do not know the url of the file that has to be downloaded. 这里的问题是我不知道必须下载的文件的URL。 It is getting passed by the website.
网站正在通过它。
For example: If I pass the following url in browser " http://www.ncdex.com/MarketDataAction_bhavCopySubmit.action " then webbrowser file download event gets fired and a save file dialog box appears. 例如:如果我在浏览器“ http://www.ncdex.com/MarketDataAction_bhavCopySubmit.action ”中传递以下网址,则会触发webbrowser文件下载事件,并出现一个保存文件对话框。 After this I have to manually click on save and then save the file to a specific path.
之后,我必须手动单击“保存”,然后将文件保存到特定路径。
I want to automate this process which means file gets saved automatically to the path I want. 我想自动化这个过程,这意味着文件会自动保存到我想要的路径。
Can this be done ? 能做到吗? Otherwise I will then have to use sendkeys to manage the dialog box which may not be easy.
否则,我将不得不使用sendkey来管理对话框,这可能并不容易。
If you're not opposed to using a different class than the WebBrowser control for this particular functionality you can leverage the WebClient class to make this easy: 如果您不反对使用与WebBrowser控件不同的类来实现此特定功能,则可以利用WebClient类来简化此工作:
Dim strURL As String = "http://www.ncdex.com/MarketDataAction_bhavCopySubmit.action"
Dim strFileLocation As String = "C:\SomeLocation\SomeFileName.SomeExtension"
Dim objWebClient As New System.Net.WebClient()
System.IO.File.WriteAllBytes(strFileLocation, objWebClient.DownloadData(strURL))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.