-1

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.

2
  • 1
    What does the code of your event handler look like? Commented Apr 21, 2015 at 8: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 Commented Apr 22, 2015 at 0:24

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.