Welcome Guest Search | Active Topics | Sign In | Register

Downloading file using WebView Options
rainstuff
Posted: Wednesday, October 19, 2016 3:05:24 AM
Rank: Advanced Member
Groups: Member

Joined: 9/20/2016
Posts: 73
Hello! Is there a way to directly and silently download a file (without dialogs) using webview and get binary data?
Tried this with no luck:

EO.WebBrowser.WebView m_WebView = new EO.WebBrowser.WebView();
m_WebView.LoadHtmlAndWait(mp3link);
var aaa = m_WebView.GetHtml();


Or maybe better to use HttpWebRequest for this purpose?
eo_support
Posted: Wednesday, October 19, 2016 9:02:34 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

First you need to use a ThreadRunner when you try to create a WebView without UI:

https://www.essentialobjects.com/doc/webbrowser/start/webview_no_ui.aspx

Next if you just want it to download a file (instead of rendering it and downloading it), you will need to use our downloading interface:

https://www.essentialobjects.com/doc/webbrowser/customize/download.aspx

Hope this helps. Please feel free to let us know if you still have any more questions.

Thanks!
rainstuff
Posted: Wednesday, October 19, 2016 9:19:11 AM
Rank: Advanced Member
Groups: Member

Joined: 9/20/2016
Posts: 73
Thank you for the answer!
I've already used HttpWebRequest. I need to load small files, and i think it's a faster way:

public byte[] getDataFromUrl(string url)
{
System.Net.HttpWebRequest request = null;
System.Net.HttpWebResponse response = null;
byte[] b = null;
request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
response = (System.Net.HttpWebResponse)request.GetResponse();
if (request.HaveResponse)
{
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
Stream receiveStream = response.GetResponseStream();
using (BinaryReader br = new BinaryReader(receiveStream))
{
b = br.ReadBytes(500000);
br.Close();
}
}
}
return b;
}
eo_support
Posted: Wednesday, October 19, 2016 9:55:29 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,229
Hi,

Yes. If you just want to download the file out right then you do not need a browser engine since the main purpose of the browser engine is to interpret, run and render the page. In some occasions you may need those features in order to properly download a file (for example, if you must go through a login page first), then you can use the browser engine to automate such task.

Thanks!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.