我想表明在C#中的Windows應用程序文件上傳進度,我使用它需要更多的時間來保存在線數據庫或upload.I現在用以下Code.I有搜索但它並沒有顯示確切的百分比明智的進展。另外我想改變文件名前移動到另一個10cation。 在此先感謝。我想表明在C#應用程序文件上傳進度
OpenFileDialog dlg = new OpenFileDialog();
DialogResult dlgRes = dlg.ShowDialog();
Application.DoEvents();
label14.Visible = true;
if (DialogResult.OK != DialogResult.Cancel)
{
foreach (string file in dlg.FileNames)
{
try
{
newpath = Path.Combine(textBox2.Text, Path.GetFileName(file)).ToString();
filenametemp = "tush" + Path.GetFileName(file).ToString();
if (String.IsNullOrEmpty(textBox2.Text))
{
MessageBox.Show("please select folder to save");
}
else
{
File.Copy(file, Path.Combine(textBox2.Text, Path.GetFileName(file)).ToString());
if (dlgRes != DialogResult.Cancel)
{
//Provide file path in txtFilePath text box.
txtFilePath.Text = dlg.FileName;
}
//string folderpath = System.IO.Directory.GetParent(Environment.CurrentDirectory).Parent.FullName + textBox2.Text;
//string filePath = textBox2.Text + System.IO.Path.GetFileName(dlg.FileName);
//System.IO.File.Copy(dlg.FileName, folderpath, true);
try
{
//Read File Bytes into a byte array
byte[] FileData = ReadFile(txtFilePath.Text);
//Initialize SQL Server Connection
SqlConnection CN = new SqlConnection(ConfigurationManager.ConnectionStrings["Copymanagment"].ConnectionString);
//Set insert query
string qry = "insert into fileinfo (File_Id,File_Path,date,OriginalPath,Billnumber,Billdate,FileData) values(@FileId,@Filepath,@Date,@OriginalPath,@Billnumber,@Billdate,@FileData)";
//Initialize SqlCommand object for insert.
SqlCommand SqlCom = new SqlCommand(qry, CN);
string path = textBox2.Text;
string[] arrpath = null;
int count;
arrpath = path.Split('\\');
for (count = 0; count <= arrpath.Length - 1; count++)
{
// MessageBox.Show(arrpath[count]);
}
string folder = arrpath[arrpath.Length - 1] + databaseid().ToString();
//We are passing Original File Path and File byte data as sql parameters.
string fileid = Path.GetDirectoryName(dlg.FileName);
SqlCom.Parameters.Add(new SqlParameter("@FileId", (object)folder));
SqlCom.Parameters.Add(new SqlParameter("@Filepath", (object)newpath));
SqlCom.Parameters.Add(new SqlParameter("@Date", (object)System.DateTime.Now.ToString("dd-MM-yyyy hh:mm:ss tt")));
SqlCom.Parameters.Add(new SqlParameter("@OriginalPath", (object)txtFilePath.Text));
SqlCom.Parameters.Add(new SqlParameter("@Billnumber", (object)textbillno.Text));
SqlCom.Parameters.Add(new SqlParameter("@Billdate", (object)dateTimePicker1.Value.ToString("dd-MM-yyyy")));
SqlCom.Parameters.Add(new SqlParameter("@FileData", (object)FileData));
//Open connection and execute insert query.
CN.Open();
SqlCom.ExecuteNonQuery();
CN.Close();
label14.Visible = false;
//Close form and return to list or Files.
MessageBox.Show("File saved Succsesfully");
txtFilePath.Text = "";
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
catch
{
MessageBox.Show("File already available");
}
}
}
做ü要顯示進度PNG或ü要顯示的文件百分比上傳? – Alex
已上傳文件的百分比 –
您是否願意使用第三方控件? – Alex