hi friends
how to use progress bar when uploading file ?
this is my code for uploading file to server
please help , thanks
how to use progress bar when uploading file ?
this is my code for uploading file to server
please help , thanks
private void btnBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Browse Text Files";
openFileDialog1.CheckFileExists = true;
openFileDialog1.CheckPathExists = true;
openFileDialog1.DefaultExt = "txt";
openFileDialog1.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
openFileDialog1.ReadOnlyChecked = true;
openFileDialog1.ShowReadOnly = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtPath.Text = openFileDialog1.FileName;
}
}
private void btnUpload_Click(object sender, EventArgs e)
{
using (Renci.SshNet.SftpClient sftp = new Renci.SshNet.SftpClient(txtHost.Text, txtUsername.Text, txtPassword.Text))
{
using (Stream fin = File.OpenRead(txtPath.Text))
{
try
{
sftp.ConnectionInfo.Timeout = new TimeSpan(0, 0, 30);
sftp.Connect();
sftp.UploadFile(fin, "/upload/" + "salam.txt");
MessageBox.Show("Uploaded Succesfull");
}
catch
{
MessageBox.Show("Uploading Error...");
}
}
}
}