C# YouTube Downloader

I write a video downloader from YouTube on lib VideoLibrary. The interface has a progress bar and two buttons + another input field, one button is download, and the second is to specify the folder where to download. I have linked a dialog box to the folder selection button, but I can't output the result from there and put the path to the folder there, and the code below gives the error

Нет перегруженного метода для "downloadik_Click", который соответствует делегату "RoutedEventHandler"
using VideoLibrary;
using Ookii.Dialogs;
using Ookii.Dialogs.Wpf;
using WinForms = System.Windows.Forms;

namespace WpfApp4
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            WinForms.FolderBrowserDialog folderDialog = new WinForms.FolderBrowserDialog();
            folderDialog.ShowNewFolderButton = false;
            folderDialog.SelectedPath = System.AppDomain.CurrentDomain.BaseDirectory;
            WinForms.DialogResult result = folderDialog.ShowDialog();
        }

        private void downloadik_Click(object sender, RoutedEventArgs e, string result)
        {
            string link = url.ToString();
            var youTube = YouTube.Default;

            var video = YouTube.Default.GetAllVideos(link).First(v => v.Resolution == 720);
            var audio = YouTube.Default.GetVideo(link);

            byte[] bytesvideo = video.GetBytes();
            File.WriteAllBytes(result + video.FullName, bytesvideo);

        }
    }
}
Author: aepot, 2020-12-03

1 answers

Save the selected path to a certain variable of your form and use it in the future. And the result argument from downloadik_Click must be removed, otherwise it cannot be a handler for the button click event. I added another check for whether the path is selected or not.

private string _curDirectorySave;

private void Button_Click(object sender, RoutedEventArgs e)
{   
    WinForms.FolderBrowserDialog folderDialog = new WinForms.FolderBrowserDialog();
    folderDialog.ShowNewFolderButton = false;
    folderDialog.SelectedPath = System.AppDomain.CurrentDomain.BaseDirectory;
    if (folderDialog.ShowDialog() == WinForms.DialogResult.OK)
         _curDirectorySave = folderDialog.SelectedPath;
}

private void downloadik_Click(object sender, RoutedEventArgs e)
{
    if (string.IsNullOrEmpty(_curDirectorySave))
    {
        MessageBox.Show("Выберите путь сохранения");
        return;
    }
    string link = url.ToString();
    var youTube = YouTube.Default;

    var video = YouTube.Default.GetAllVideos(link).First(v => v.Resolution == 720);
    var audio = YouTube.Default.GetVideo(link);

    byte[] bytesvideo = video.GetBytes();
    File.WriteAllBytes(_curDirectorySave + video.FullName, bytesvideo); 
}
 4
Author: Pavel Popov, 2020-12-03 07:44:57