Welcome Guest Search | Active Topics | Sign In | Register

vb.net and Options
RedCarpet
Posted: Monday, April 22, 2024 8:47:04 AM
Rank: Newbie
Groups: Member

Joined: 4/22/2024
Posts: 7
Hello im making a vb.net app with EO web browser

I need take control of downloading file (webbrowser will navigate only in our own website asp.net)

Now i inserted webbrowser and im able to navigate but i need help ( i have not found example) how to use WebView.BeforeDownload Event to intercept file before downloading.

I implemented EO webbrowser succesfully and im able to navigate in website i decide

Now my problem is i need some example code to manage downloading file contro ( before download) in vb.net


Here my simple code:

Imports System.Net
Imports System.ComponentModel
Imports EO

Public Event BeforeDownload As EO.WebBrowser.BeforeDownloadHandler

Public Class Form1
Private m_WebView As New EO.WebBrowser.WebView

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Initialize the WebView using the PictureBox's window handle
m_WebView.Create(PictureBox1.Handle)

'Load page
m_WebView.Url = "www.website.xxx/customer.aspx"
End Sub
End Class



eo_support
Posted: Tuesday, April 23, 2024 1:24:15 PM
Rank: Administration
Groups: Administration

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

I am not exactly sure if I understand your question. When the browser requests a Url from the server, the result will be either "dispalyed" or "downloaded". When the resource is "downloaded", the browser engine will display a "Save As" dialog for you save the file instead of displaying it.

By default, a file that can be displayed by the browser will be automatically displayed instead of downloaded. For example, if you open a HTML file, it will be displayed. You can force the browser engine to download. On the other hand, a file that can not be displayed by the browser will be automatically downloaded. For example, if you open a zip file, the browser will use the "download" flow and display a "Save As" dialog for you to save the zip file.

EO.WebBrowser provides two features related to download:

1. ShouldForceDownload event for you to force download for a resource that otherwise would have been displayed:

https://www.essentialobjects.com/doc/eo.webbrowser.webview.shouldforcedownload.html

2. Download progress events for you to monitor/display download progress:

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

Download progress event (such as BeforeDownload) will NOT fire for a file that is not handled as a downoad. For example, if you open a HTML file, the browser will just display it instead of "downloading" it. In this case none of the download progress event will fire.

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

Thanks!
RedCarpet
Posted: Tuesday, April 23, 2024 1:38:28 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2024
Posts: 7
Hello

Take point im building an executable called "my_exe" on vb.net with inside webbrowser EO control

what i have to do :

-from webbrowser i will download a file from my own website
-we must not have download savedialog window of browser
-in silent mode i want save file downoaded file on array on the "my_exe" executable, that is hosting webbrowser.
-decript file with internal algo of my_exe
-then purpose classic windows savedialog with decripted file

For other info im here

eo_support
Posted: Wednesday, April 24, 2024 9:37:22 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,088
Does the file download correctly when you open it with Google Chrome browser?
RedCarpet
Posted: Wednesday, April 24, 2024 10:01:52 AM
Rank: Newbie
Groups: Member

Joined: 4/22/2024
Posts: 7
Yes download starts correctly
eo_support
Posted: Wednesday, April 24, 2024 10:34:28 AM
Rank: Administration
Groups: Administration

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

You need to explicitly hook up your event handler with the following code:

Code: Visual Basic.NET
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    'Initialize the WebView using the PictureBox's window handle
    m_WebView.Create(PictureBox1.Handle)

    'Add Event Handler
    AddHandler m_WebView.BeforeDownload, New BeforeDownloadHandler(AddressOf  WebView_BeforeDownload)
End Sub

Private Sub WebView_BeforeDownload(sender As Object, e As BeforeDownloadEventArgs)
   ...before download handler...
End Sub


You can find more sample code inside TabbedBrowser_VB sample in MainWindow.xaml.vb.

Thanks!
RedCarpet
Posted: Wednesday, April 24, 2024 12:50:43 PM
Rank: Newbie
Groups: Member

Joined: 4/22/2024
Posts: 7
Hello i had to add delcaration before your code

Imports System.Net
Imports System.ComponentModel
Imports EO
Imports EO.WebBrowser

So it worked and msg box display correctly

Now can you help me finding way how to download file in byte array of my executable instead of showing prompt save file as?

Thanks
eo_support
Posted: Wednesday, April 24, 2024 12:57:28 PM
Rank: Administration
Groups: Administration

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

You need to:

1. Handle BeforeDownload event and set e.ShowDialog to false in your handler. This will tell the browser engine NOT to show the Save As dialog and proceed to save the download into a temp file;
2. Handle DownloadCompleted event and then use e.Item.FullPath to get the full path of the temp file.

Now the temp file contains the fully downloaded file and then you can do whatever you want to do with it. For example, you can move the file to a different location, or read it to a byte array, etc. This part would no longer has anything to do with our product.

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.