我想寫入我的uploadProgress
進度條工具提示當前上傳量,因此當用戶鼠標懸停進度條時,可以看到更改顯示上傳量的工具提示文件大小。 我到目前爲止的代碼給我「忙」圖標時,我將鼠標懸停,直到文件完成上傳,然後它顯示下載的數量和文件大小。C#FtpWebRequest進度條工具提示更新與上傳量
有人可以幫我搞定這個工作嗎?
private void uploadFile()
{
try
{
richTextBox1.AppendText("\n\nStarting file upload");
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create("ftp://ftpsite.com/public_html/test.htm");
request.Credentials = new NetworkCredential("username", "password");
request.UsePassive = true;
request.UseBinary = true;
request.KeepAlive = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
using (Stream fileStream = File.OpenRead(@"C:\path\testfile.UPLOAD"))
using (Stream ftpStream = request.GetRequestStream())
{
uploadProgress.Invoke(
(MethodInvoker)delegate {
uploadProgress.Maximum = (int)fileStream.Length; });
byte[] buffer = new byte[10240];
int read;
while ((read = fileStream.Read(buffer, 0, buffer.Length)) > 0)
{
ftpStream.Write(buffer, 0, read);
uploadProgress.Invoke(
(MethodInvoker)delegate {
uploadProgress.Value = (int)fileStream.Position;
toolTip1.SetToolTip(
uploadProgress, string.Format("{0} MB's/{1} MB's\n",
(uploadProgress.Value/1024d/1024d).ToString("0.00"),
(fileStream.Length/1024d/1024d).ToString("0.00")));
});
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
感謝
向我們展示如何調用'uploadFile'。 –