webclient下载+进度

public DownTemplateView()

        {

            InitializeComponent();

            System.Net.WebClient c = new System.Net.WebClient();

            string path = Environment.CurrentDirectory + "\\Record\\" + CommonHelper.ClassID + "\\";

            if (!System.IO.Directory.Exists(path))

                System.IO.Directory.CreateDirectory(path);

            c.DownloadFileAsync(new Uri(CommonHelper.TemplateDownPath), path+ System.IO.Path.GetFileName(CommonHelper.TemplateDownPath));

            c.DownloadProgressChanged += new System.Net.DownloadProgressChangedEventHandler(c_DownloadProgressChanged);

            c.DownloadFileCompleted += new AsyncCompletedEventHandler(c_DownloadFileCompleted);

            c.Proxy = WebRequest.DefaultWebProxy;

        }

        void c_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)

        {

            MessageBox.Show("ok");

        }

        void c_DownloadProgressChanged(object sender, System.Net.DownloadProgressChangedEventArgs e)

        {

            prcs.Value = e.ProgressPercentage;

            this.label1.Content = "已完成:" + prcs.Value.ToString() + "%";

        }

 

你可能感兴趣的:(client)