如果站点提供下载文件,我如何添加到此代码 CefSharp,它下载到文件夹
C:/Gwlo/Common
,如果没有文件夹,它会创建它?下载后还打开这个文件吗?我只是没有在任何论坛上找到这个问题
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CefSharp;
using CefSharp.WinForms;
using CefSharp.Wpf;
namespace KaindLauncher
{
public partial class Kaind : Form
{
public Kaind()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
chromiumWebBrowser1.Load("https://google.com");
}
private void chromiumWebBrowser1_LoadingStateChanged(object sender, CefSharp.LoadingStateChangedEventArgs e)
{
}
}
}
我试过这段代码,但出现错误:
string downloadFolderPath = @"C:\Kaind\Downloads\Common\";
if (!Directory.Exists(downloadFolderPath))
{
Directory.CreateDirectory(downloadFolderPath);
}
var settings = new DownloadSettings
{
DefaultFileName = "downloaded_file",
SaveFileDialog = new SaveFileDialog()
{
InitialDirectory = downloadFolderPath,
OverwritePrompt = true
}
};
chromiumWebBrowser1.DownloadHandler = new DownloadHandler(settings);