0

I am having issues in knowing the percentage of a file sent at any point the FileTransferProgressEventArgs event is fired using WinSCP .NET assembly in C#.

The FileProgress returns only 0 or 1, or the documentation said (0-1) which I don't understand. I need to know how much bytes of the file is sent but not 0,1 which i don't understand. I know CPS is the bytes per second but i need more variables.

The method where i increment the progress bar is as below void

SessionFileTransferProgress(object sender, FileTransferProgressEventArgs e)
{
    progressBar.Increment((int)e.FileProgress);
} 

Its e.FileProgress and e.CPS which I thought could help but seems I'm missing something.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 1
    What does the code of your event handler look like? – Thomas Lielacher Apr 21 '15 at 08:40
  • The method where i increment the progress bar is as below void SessionFileTransferProgress(object sender, FileTransferProgressEventArgs e) { progressBar.Increment((int)e.FileProgress); } its e.FileProgress and e.CPS which i thought could help but seems i'm missing something – Amadou Bah Apr 22 '15 at 00:24

1 Answers1

1

The problem is, that you cast e.FileProgress to int. As you allready said, the documentation specifies that the value of e.FileProgress ranges from 0 to 1, for example 0.55. If you cast this value to an integer, you will lose all decimal places. So the resulting value will be 0. To solve this problem you can transform e.FileProgress into a percentage value by multiplying it with 100. So you get values ranging from 0 to 100. So you can implement your event handler like so:

void SessionFileTransferProgress(object sender, FileTransferProgressEventArgs e) 
{
    progressBar.Value = (int)(e.FileProgress * 100);
}

You just have to make sure, that the Minimum and Maximum properties of your progress bar are set to their default values 0 and 100.

Thomas Lielacher
  • 1,037
  • 9
  • 20