0

I use dotnetbrowser to display a web browser on a old windows framework. have you an idea to define the download path ? My dotnetbroser is enable, i can show my webpage but i don't found in documentation or exemple how define this simple download path.

The only exemple that i've found is about the download event detection. I use WPF in C#

Thanks.

jfc
  • 1
  • 1

2 Answers2

0

The DotNetBrowser.DownloadItem.DestinationFile property is writable and can be used to configure the path to store the file.

To set this property in your application, you need to subclass the DotNetBrowser.DefaultDownloadHandler and implement its AllowDownload(DownloadItem) method. Then you need to configure your download handler as shown in the documentation article: File Download

You can also configure and use DotNetBrowser.WPF.WPFDefaultDownloadHandler instance to show file chooser and select the path to store the file.

Anna Dolbina
  • 1
  • 1
  • 8
  • 9
0
  • This is a solution

Défine your browser like variable :

BrowserView myBrowserView;
Browser myBrowser;

Create the browser properly :

this.myBrowser = BrowserFactory.Create();
this.myBrowserView = new WPFBrowserView(this.myBrowser);

Create event detection for download

this.myDowloadHandler = new SampleDownloadHandler();
this.myBrowser.DownloadHandler = myDowloadHandler;

Add it to a container, here, a grid

grid_navigateur.Children.Add((UIElement)myBrowserView.GetComponent());

Now we are going to use our "SampleDownloadHandler" class

class SampleDownloadHandler : DownloadHandler
{
    public bool AllowDownload(DownloadItem download)
    {
      download.DestinationFile = "exemple\of\path\whith\file\name";

        download.DownloadEvent += delegate(object sender, DownloadEventArgs e)
        {
            DownloadItem downloadItem = e.Item;
            if (downloadItem.Completed)
            {
                System.Windows.MessageBox.Show("Download complete");
            }
        };

        return true;
    }

My personalisated class define path and name of the file who is download and pop a message when is over.

(to found the file name, you do to cut the string download.DestinationFile after the last )

jfc
  • 1
  • 1