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() + "%";
        }

 

posted @ 2013-03-26 13:18  红鲤鱼与驴与绿鲤鱼  阅读(488)  评论(0编辑  收藏  举报