Click here to Skip to main content
15,892,059 members
Articles / Programming Languages / C#

FTP Client and HttpFileDownloader Components (Controls)

Rate me:
Please Sign up or sign in to vote.
4.81/5 (15 votes)
25 Jun 2008CPOL3 min read 83.3K   7K   103  
FTP client and HttpFileDownloader components (controls).
// This is a part of DotNetRemoting Library
// Copyright (C) 2002-2008 Amplefile
// All rights reserved.
//
// This source code can be used, distributed or modified
// only under terms and conditions 
// of the accompanying license agreement.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace HttpDownloaderDemo
{
    public partial class HttpFileDownloaderForm : GenericSaveForm.GenericSavForm
    {
        public HttpFileDownloaderForm()
        {
            InitializeComponent();
        }

        private void button_start_Click(object sender, EventArgs e)
        {
            if (button_start.Text == "Start")
            {
                httpDownloader1.URLDownload = textBox_url.Text;
                httpDownloader1.SetLocalFolder( textBox_loc_folder.Text);
                httpDownloader1.Start();
                button_start.Text = "Abort";
            }
            else
            {
                httpDownloader1.Abort();
                button_start.Text = "Start";
            }
        }

        private void httpDownloader1_StatusUpdateEvent(string Message, DotNetRemoting.DStatus Status, long FullSize, long CurrentBytes, TimeSpan EstimatedTimeLeft, double Speed)
        {
            toolStripStatusLabel_stat.Text = Message;

            toolStripStatusLabel_time_left.Text = DotNetRemoting.BaseDownloader.TimeSpanToString(EstimatedTimeLeft);

            toolStripStatusLabel_speed.Text = Speed.ToString("F1") + " Kb/s";

            if (Status == DotNetRemoting.DStatus.complete || 
                Status == DotNetRemoting.DStatus.error || 
                Status == DotNetRemoting.DStatus.timeout )
            {
                button_start.Text = "Start";
            }
        }

        private void HttpFileDownloaderForm_Load(object sender, EventArgs e)
        {
            _DownloaderSettings = (DownloaderSettings)GetSettingsObject(typeof(DownloaderSettings));
            textBox_loc_folder.Text = _DownloaderSettings.LocalFolder;
            textBox_url.Text = _DownloaderSettings.URL;
        }

        DownloaderSettings _DownloaderSettings;

        protected override void OnFormClosing(FormClosingEventArgs e)
        {
            _DownloaderSettings.LocalFolder = textBox_loc_folder.Text;
            _DownloaderSettings.URL = textBox_url.Text;
            base.OnFormClosing(e);
        }

        private void button_browse_Click(object sender, EventArgs e)
        {
            folderBrowserDialog1.SelectedPath = _DownloaderSettings.LocalFolder;

            if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
            {
                _DownloaderSettings.LocalFolder = folderBrowserDialog1.SelectedPath;
                textBox_loc_folder.Text = _DownloaderSettings.LocalFolder;
            }
        }
    }

    #region App settings container
    [Serializable]
    public class DownloaderSettings
    {
        public string URL = "http://dotnetremoting.com/Download/SerializationStudioSetup.exe";
        public string LocalFolder;
    }
    #endregion
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Australia Australia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions