Hi guys need urgent help.
I am making a youtube downloader that downloads two or more videos from Youtube at the same time and I don't how to do it using System.Net.Webclient in C#.Net.

Please post a code snippet. HELP!

Recommended Answers

All 5 Replies

Member Avatar for stbuchok

Just thought I'd let you know that no one is going to just give you all the code for this. You need to try this stuff out on your own, then when you get stuck on a specific part, ask questions about that specific part.

If you'd like, post the code you have so far (not everything, just the parts that are important) and point out the part that isn't working and the error messages you get.

You will get much more help here if you show that you are doing work yourself and not just asking the community to do your job for you.

OK.Here's the part of the code.

try
        {
            wc = new WebClient();
            wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
            wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
            lnkCancel.Enabled = true;
            wc.DownloadFileAsync(new Uri(link), dwnFile);
            lblResult.Visible = false;
        }
        catch (Exception)
        {
            MessageBox.Show("  Unexpected error occured.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            try { File.Delete(dwnFile); if (_audio) File.Delete(filePath); }
            catch (Exception) { }
            unlockGui();
        }
        lblResult1.Text = "";

And here's the code for the DownloadFileCompleted

void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        lnkCancel.Enabled = false;

        if (e.Cancelled)
        {
            MessageBox.Show("Download canceled.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            try
            {
                File.Delete(dwnFile);
                if (_audio) File.Delete(filePath);
            }
            catch (Exception) { }
            unlockGui();
            return;
        }
        wc = null;
        try
        {
            FileInfo f = new FileInfo(dwnFile);
            if (f.Length < 4)
            {
                MessageBox.Show("  Error occured during download.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                f = null;
                try
                {
                    if (_audio) File.Delete(filePath); File.Delete(dwnFile);
                }
                catch (Exception) { }
            }
            else
            {
                f = null;
                progressBar1.Value = 0;
                if (_audio)
                {
                    toMp3(dwnFile);
                    try { File.Delete(dwnFile); }
                    catch (Exception) { }
                }
                this.Activate();
            }
        }
        catch (Exception ex)
        {
            this.Activate();
            MessageBox.Show("Error: " + ex.Message, Application.ProductName);
        }
        unlockGui();
        lblResult.Text = "Done ";
    }

Please help me. Hope this is enough.

OK.Here's the part of the code.

try
        {
            wc = new WebClient();
            wc.DownloadProgressChanged += new DownloadProgressChangedEventHandler(wc_DownloadProgressChanged);
            wc.DownloadFileCompleted += new AsyncCompletedEventHandler(wc_DownloadFileCompleted);
            lnkCancel.Enabled = true;
            wc.DownloadFileAsync(new Uri(link), dwnFile);
            lblResult.Visible = false;
        }
        catch (Exception)
        {
            MessageBox.Show("  Unexpected error occured.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
            try { File.Delete(dwnFile); if (_audio) File.Delete(filePath); }
            catch (Exception) { }
            unlockGui();
        }
        lblResult1.Text = "";

And here's the code for the DownloadFileCompleted

void wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
    {
        lnkCancel.Enabled = false;

        if (e.Cancelled)
        {
            MessageBox.Show("Download canceled.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
            try
            {
                File.Delete(dwnFile);
                if (_audio) File.Delete(filePath);
            }
            catch (Exception) { }
            unlockGui();
            return;
        }
        wc = null;
        try
        {
            FileInfo f = new FileInfo(dwnFile);
            if (f.Length < 4)
            {
                MessageBox.Show("  Error occured during download.", Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error);
                f = null;
                try
                {
                    if (_audio) File.Delete(filePath); File.Delete(dwnFile);
                }
                catch (Exception) { }
            }
            else
            {
                f = null;
                progressBar1.Value = 0;
                if (_audio)
                {
                    toMp3(dwnFile);
                    try { File.Delete(dwnFile); }
                    catch (Exception) { }
                }
                this.Activate();
            }
        }
        catch (Exception ex)
        {
            this.Activate();
            MessageBox.Show("Error: " + ex.Message, Application.ProductName);
        }
        unlockGui();
        lblResult.Text = "Done ";
    }

Please help me. Hope this is enough.

Member Avatar for stbuchok

Is there an error message you are getting?

yes..like that ERROR:Download file argument

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.