Пример #1
0
 /// <summary>
 /// Compares two URL objects
 /// </summary>
 public static bool operator !=(URL URL1, URL URL2)
 {
     if ((object)URL1 == null && (object)URL2 != null)
     {
         return(true);
     }
     if ((object)URL2 == null && (object)URL1 != null)
     {
         return(true);
     }
     if ((object)URL1 == null && (object)URL2 == null)
     {
         return(false);
     }
     return(URL1.ToString() != URL2.ToString());
 }
Пример #2
0
        /// <summary>
        /// This method will be invoked when we press the Download button.
        /// Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                string name1 = null;
                string name2 = null;
                URL1 = textBox1.Text;
                URL2 = textBox2.Text;

                if (URL1 != "")
                {
                    label3.Visible       = true;
                    progressBar1.Visible = true;
                    if (URL1.Contains("youtube"))
                    {
                        string[] split  = URL1.Split('%', '/');
                        int      length = split.Length;

                        name1 = split[length - 1];

                        //create a instance of web client
                        WebClient client = new WebClient();

                        MessageBox.Show("File1 is video");

                        //Start the Download
                        client.DownloadFileAsync(new Uri(URL1), @"C: \Users\Public\mp$File.mp4");
                        //
                        client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted1);
                        //To see the progress
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged1);
                    }
                    else if (URL1.Contains(".exe") || URL1.Contains(".Zip"))
                    {
                        // Create an instance of WebClient
                        String[] split   = URL1.Split('%', '/');
                        int      length1 = split.Length;
                        name1 = split[length1 - 1];

                        WebClient client = new WebClient();

                        // All for URL1
                        MessageBox.Show("file1 is application");
                        // Hookup DownloadFileCompleted Event
                        client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted1);
                        //progress bar
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged1);
                        // Start the download
                        client.DownloadFileAsync(new Uri(URL1), @"C:\Users\Public\File1");
                    }
                    else
                    {
                        // Create an instance of WebClient
                        String[] split   = URL1.Split('%', '/');
                        int      length1 = split.Length;
                        name1 = split[length1 - 1];
                        WebClient client = new WebClient();

                        // All for URL1
                        MessageBox.Show("file name 1 is \n");
                        // Hookup DownloadFileCompleted Event
                        client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted1);
                        //progress bar
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged1);
                        // Start the download
                        client.DownloadFileAsync(new Uri(URL1), @"C: \Users\Public\empty1" + " ");
                    }
                }

                if (URL2 != "")
                {
                    label4.Visible       = true;
                    progressBar2.Visible = true;
                    if (URL2.Contains("youtube"))
                    {
                        string[] split  = URL2.Split('%', '/');
                        int      length = split.Length;

                        name2 = split[length - 1];

                        //create a instance of web client
                        WebClient client = new WebClient();

                        MessageBox.Show("File2 is video");

                        //Start the Download
                        client.DownloadFileAsync(new Uri(URL2), @"C: \Users\Public\mp4File.mp4");
                        //
                        client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted2);
                        //To see the progress
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged2);
                    }
                    else if (URL2.Contains(".exe"))
                    {
                        // Create an instance of WebClient
                        String[] split   = URL2.Split('%', '/');
                        int      length1 = split.Length;
                        name2 = split[length1 - 1];
                        WebClient client = new WebClient();

                        // All for URL2
                        MessageBox.Show("file2 is application");

                        // Hookup DownloadFileCompleted Event
                        client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCompleted2);
                        //progress bar
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged2);
                        // Start the download
                        client.DownloadFileAsync(new Uri(URL2), @"C:\Users\Public\exeFile2");
                    }
                    else
                    {
                        // Create an instance of WebClient
                        String[] split   = URL2.Split('%', '/');
                        int      length1 = split.Length;
                        name2 = split[length1 - 1];
                        WebClient client = new WebClient();

                        // All for URL2
                        MessageBox.Show("file2 is \n");
                        // Delegate instantiation
                        //Attach your event handler to event
                        client.DownloadFileCompleted += new   AsyncCompletedEventHandler(DownloadFileCompleted2);
                        //progress bar
                        client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressChanged2);
                        // Start the download
                        client.DownloadFileAsync(new Uri(URL2), @"C: \Users\Public\empty2" + "");
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message + " ");
            }
        }