|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
I want to use specific methods before file starting download. But BeforeDownloadEvent not work for me because it's not suspend download and while I use my methods, file has been downloaded, and it's broke my code. I found this post, and it's sad for me. Can you help me with this issue? I can cancel download item, but can't resume, any solution?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
No. Currently you can not pause the download. You either cancel it all together or let it continue until finish.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 5/9/2016 Posts: 84
|
Hi, I am interested in this as well and currently it is not normal browser behavior and can cause strange problems when download sites redirect to thank you page. It must be some programatic solution to this. At least hang the download thread some way?
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
I tested with latest build (16.1.54) with pause and resume methods and I can't set a download path. I used to set the path BeforeDownload event and BeforeDownloadEventArgs.FullPath property, now it's not work, it's a bug, or I must to do something else?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
We have confirmed this to be a bug. We will fix it and post an update build this week.
Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
This is just to let you know that we have posted a new build that should fix the FullPath issue. You can download the new build from our download page.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
It's work fine, thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Great. Thanks for confirming the fix!
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
Hi again, I still have a problems with download. the code doesn't work and file didn't download to the folder:
Code: C#
private void Form1_Load(object sender, EventArgs e)
{
webControl1.WebView.DownloadUpdated += WebViewOnDownloadUpdated;
webControl1.WebView.BeforeDownload +=WebViewOnBeforeDownload;
}
private void WebViewOnBeforeDownload(object sender, BeforeDownloadEventArgs beforeDownloadEventArgs)
{
beforeDownloadEventArgs.Item.Pause();
Console.WriteLine("before");
beforeDownloadEventArgs.ShowDialog = false;
beforeDownloadEventArgs.FilePath = @"C:\Users\AiSatan\Downloads\test.exe";
beforeDownloadEventArgs.Item.Resume();
}
private void WebViewOnDownloadUpdated(object sender, DownloadEventArgs downloadEventArgs)
{
Console.WriteLine("update");
}
//Output:
//
//before
//update
As you can see, update event fires only once (I think after Pause or Resume methods) If I use only this:
Code: C#
private void Form1_Load(object sender, EventArgs e)
{
webControl1.WebView.DownloadUpdated += WebViewOnDownloadUpdated;
webControl1.WebView.BeforeDownload +=WebViewOnBeforeDownload;
}
private void WebViewOnBeforeDownload(object sender, BeforeDownloadEventArgs beforeDownloadEventArgs)
{
Console.WriteLine("before");
beforeDownloadEventArgs.ShowDialog = false;
beforeDownloadEventArgs.FilePath = @"C:\Users\AiSatan\Downloads\test.exe";
}
private void WebViewOnDownloadUpdated(object sender, DownloadEventArgs downloadEventArgs)
{
Console.WriteLine("update");
}
//Output:
//
//before
file downloaded correct, but DownloadUpdated never called.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi, Not all downloads trigger DownloadUpdated event. When the download starts, the web server can send down the total size of the file to be downloaded or not. If it does send total size of the file, then the browser engine will be able to calculate the progress based on the number of bytes it has received. When this is the case, DownloadUpdated is called. If the server does not send the total size of the file, then the browser engine can not calculate the progress thus it does not trigger DownloadUpdated event. You can test the event with our own TabbedBrowser sample change the code in WebView_BeforeDownload from:
To:
Code: C#
e.ShowDialog = false;
e.FilePath = your_file_path;
You can then use it to download the file from our download page and you should be able to see the download progress get correctly updated. Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
Ok, I will look the sample proj. But why the file still download to temp folder if I use the new methods?
Code: C#
private void Form1_Load(object sender, EventArgs e)
{
webControl1.WebView.DownloadUpdated += WebViewOnDownloadUpdated;
webControl1.WebView.DownloadCompleted += WebViewOnDownloadCompleted;
webControl1.WebView.BeforeDownload += WebViewOnBeforeDownload;
}
private void WebViewOnDownloadCompleted(object sender, DownloadEventArgs downloadEventArgs)
{
Console.WriteLine("path: {0}", downloadEventArgs.Item.FullPath);
}
private void WebViewOnBeforeDownload(object sender, BeforeDownloadEventArgs beforeDownloadEventArgs)
{
beforeDownloadEventArgs.Item.Pause();
Console.WriteLine("before");
beforeDownloadEventArgs.ShowDialog = false;
beforeDownloadEventArgs.FilePath = @"C:\Users\AiSatan\Downloads\test.exe";
beforeDownloadEventArgs.Item.Resume();
}
private void WebViewOnDownloadUpdated(object sender, DownloadEventArgs downloadEventArgs)
{
Console.WriteLine("update");
}
//Output:
//before
//update
//path: C:\Users\AiSatan\AppData\Local\Temp\calc.exe
In your tabbrowser sample too
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
Do not call Pause/Resume in your BeforeDownload handler. Just set ShowDialog and set FilePath and you should be all fine.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 2/11/2016 Posts: 35
|
and.. where I must to use the methods? just I want to pause download before it start any downloads to my temp folder.
|
|
Rank: Advanced Member Groups: Member
Joined: 5/9/2016 Posts: 84
|
There seems to be a misunderstanding here. Here is what we are trying to achieve;
1. we click on a link 2. now it auto-downloads in temp folder - this is not what we want. We want to open our own dialog and set the download location - then start download
How do you mean we can set download path when it auto-starts downloading to the wrong path?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Hi,
You are thinking too much about "now it auto-downloads in temp folder - this is not what we want". The download will always start to a temp folder. The difference is when the download is done, where it moves that temp file to.
If you just want to change the "Save As" dialog, you do not need to handle BeforeDownload event at all. You can just handle FileDialog event and show your own dialog in that event handler.
Thanks!
|
|
Rank: Advanced Member Groups: Member
Joined: 5/9/2016 Posts: 84
|
Thanks, it works as expected now.
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,229
|
Great. Glad to hear that! Please feel free to let us know if you have any more questions.
|
|