Reputation: 229
I have created project to transferring file from client to server. I have done file transferred and got file transferred details such as file name (something.avi) and percentage (10%) of file transferred like below, Whenever I'm transferring a file, I'm using below event handler for knowing the file transferred details.
private static void SessionFileTransferProgress(object sender, FileTransferProgressEventArgs e)
{
// New line for every new file
if ((_lastFileName != null) && (_lastFileName != e.FileName))
{
Console.WriteLine();
}
// Print transfer progress
Console.Write("\r{0} ({1:P0})", e.FileName, e.FileProgress);
// Remember a name of the last file reported
_lastFileName = e.FileName;
}
private static string _lastFileName;
I need to bind this transferred details in window. I have done binding while file transferred. But I need how to bind every second file transferred details in window using WPF. Because I need to show progress of file transferring.
Upvotes: 2
Views: 589
Reputation: 202360
The WinSCP .NET assembly Session.FileTransferProgress
event is triggered continuously.
So all you need to do, is to update your control in the event handler.
As the event is triggered on a background thread, you need to use Invoke
. See Updating GUI (WPF) using a different thread.
For an example WinForms code, see WinSCP article Displaying FTP/SFTP transfer progress on WinForms ProgressBar. With WPF, the code will be very similar.
Upvotes: 2
Reputation: 229
I have found the code for display file transfer progress with percentage. Please find the below both Xaml and c# code for wpf window.
Xaml for percentage display in window using wpf.
<TextBlock x:Name="percentage" Text="" Height="27" Width="50" FontSize="20"/>
C# code for binding the file transfer progress in percentage.
this.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
{
this.percentage.Text = ((e.FileProgress * 100).ToString() + "%");
}));
Upvotes: 1
Reputation: 229
I have found the solution with help of @Martin Prikryl..Please find below code
progressBar.Dispatcher.Invoke(() => progressBar.Value = (int)(e.FileProgress * 100), DispatcherPriority.Background);
This is for progress bar moving with file trasnfer progress..I will post once done the display progress in percentage.
progressBar is name of Xaml element in wpf.
Upvotes: 2