Click or drag to resize

Downloading files

Loading web pages and downloading files

Downloading files

If you want to open a web page in the web browser, we first need to get the browser interface. As with the other Interfaces, we get this from IScripting using the GetBrowser(). You will get a ChromiumWebBrowser interface. This interface is a standard interface for the Chromium web browser. Read more about the Chromium web browser at https://cefsharp.github.io/ and Google for the official documentation ( ChromiumWebBrowser Class (cefsharp.github.io) ).

The WebBrowser property is of type IWebBrowser and has a function Load to load a web page into the browser.

Here is a short snippet to open a web page in the web window.

C#
using System.Runtime;
using System.Collections.Generic;
using VideoCataloger;
using VideoCataloger.RemoteCatalogService;

class Script
{
  static public async System.Threading.Tasks.Task Run ( IScripting scripting, string arguments ) 
  {
    var browser = scripting.GetBrowser();
    browser.WebBrowser.Load("https://videocataloger.com");
  }
}

An alternative to using the integrated browser is to use the network functions in .net. You can find these functions in the System.net namespace. For more information about these functions, look at the Microsoft documentation, Network Programming in the .NET Framework | Microsoft Docs

Here is a simple sample to download a file.

C#
using System.Runtime;
using System.Collections.Generic;
using VideoCataloger;
using VideoCataloger.RemoteCatalogService;
using System.Net;

class Script
{
  static public async System.Threading.Tasks.Task Run ( IScripting scripting, string arguments ) 
  {
    using (var client = new WebClient()) 
    {
        client.Credentials = new NetworkCredential("username", "password"); 

        try
        {
            client.DownloadFile("https://complete_url_to_the_file_you_want_to_download/", "c:\\complete_path_to_where_to_save_the_file");
        }
        catch (WebException ex)
        {
            scripting.GetConsole().WriteLine( ex.Message );
        }
    }
  }
}