PDA

View Full Version : سوال: مشکل در progress bar



terrorhell
چهارشنبه 16 مهر 1393, 12:26 عصر
سلام دوستان من دارم با استفاده از کد زیر یک فایل رو آپلود میکنم میخوام حالا progress bar داشته باشم واسه آپلودم

ممنون میشم راهنمایی کنید



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...");
}
}
}
}

juza66
چهارشنبه 16 مهر 1393, 12:39 عصر
سلام


فیلم آموزشی کار با progress bar
http://www.daneshjooyar.com/%D9%81%DB%8C%D9%84%D9%85-%D8%A2%D9%85%D9%88%D8%B2%D8%B4-%DA%A9%D8%A7%D8%B1-%D8%A8%D8%A7-progressbar/

terrorhell
چهارشنبه 16 مهر 1393, 12:53 عصر
مرسی دوست خوبم ولی کار با progress bar رو بلدم ولی نمیدونم چطوری باید واسه آپلود ازش استفاده کنم

juza66
چهارشنبه 16 مهر 1393, 13:14 عصر
یه همچین چیزیه فکر کنم



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();

this.ProgressBar1.Value = 0;
this.progressBar1.PerformStep();
sftp.UploadFile(fin, "/upload/" + "salam.txt");
MessageBox.Show("فایل با موفقیت آپلو شد","Take Backup",MessageBoxButtons.OK,MessageBoxIcon.Asteri sk);
this.progressBar1.Value = 100;


}
catch
{
MessageBox.Show("Uploading Error...");
}
}
}
}

terrorhell
چهارشنبه 16 مهر 1393, 14:43 عصر
نه اینجوری نشد

juza66
چهارشنبه 16 مهر 1393, 17:10 عصر
فایل تون حجمش زیاده برای آپلود یا کمه؟!

تحت وبه یا ویندوز؟!

terrorhell
چهارشنبه 16 مهر 1393, 22:39 عصر
فایل تون حجمش زیاده برای آپلود یا کمه؟!

تحت وبه یا ویندوز؟!


تو سرور sftp با سیستم عامل linux centos

حجم فایل هم متغیر هست ممکنه زیاد باشه و کم باشه ...