c#link progess bar with file upload

时间:2017-08-31 16:17:08

标签: c# ftp

我有一个调用上传文件的方法(应该是这样)。

       private void uploadFile()
    {

        try
        {
            richTextBox1.AppendText("\n\nStarting file upload");
            FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://ftpservername.com/test.htm");
            request.Credentials = new NetworkCredential("myusername", "mypassword");
            request.UsePassive = true;
            request.UseBinary = true;
            request.KeepAlive = true;
            request.Method = WebRequestMethods.Ftp.UploadFile;

            FtpWebResponse response = (FtpWebResponse)request.GetResponse();

            Stream responseStream = response.GetResponseStream();
            StreamReader reader = new StreamReader(responseStream);

            richTextBox1.AppendText(reader.ReadToEnd());

            richTextBox1.AppendText("\n\nUpload Complete");

            reader.Close();
            response.Close();
            request = null;
        }


        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

我还有一个进度条(标记为uploadProgress),我想显示它还要上传多少。

我有一个下载部分也有一个进度条的工作链接,代码来自此页面

  

https://www.fluxbytes.com/csharp/how-to-download-a-file-in-c-progressbar-and-download-speed/

但我看不到如何使用

    progressBar.Value = e.ProgressPercentage;

Show the percentage on our label.     labelPerc.Text = e.ProgressPercentage.ToString() + "%";       // Update the label with how much data have been downloaded so far and the total size of the file we are currently downloading     labelDownloaded.Text = string.Format("{0} MB's / {1} MB's",         (e.BytesReceived / 1024d / 1024d).ToString("0.00"),         (e.TotalBytesToReceive / 1024d / 1024d).ToString("0.00"));

进入我现有的上传方法。

有人可以帮助我吗?

0 个答案:

没有答案