试试下面的代码,你会得到更好的性能:
private void Upload144_Click(object sender, EventArgs e)
{
OpenFileDialog fileobj = new OpenFileDialog();
fileobj.InitialDirectory = "C:\\";
//fileobj.Filter = "Video files (*.mp4)";
//fileobj.ShowDialog();
if (fileobj.ShowDialog() == DialogResult.OK)
{
if (fileobj.CheckFileExists)
{
string test = Properties.Settings.Default.Connection;
SqlConnection con = new SqlConnection(test);
con.Open();
string correctfilename = System.IO.Path.GetFileName(fileobj.FileName);
SqlCommand cmd = new SqlCommand("Insert into Path(ID,Path5) VALUES ((select isnull(MAX(id),0) + 1 from Path),'\\Videos\\" + correctfilename + "')", con);
cmd.ExecuteNonQuery();
string path = Application.StartupPath.Substring(0, Application.StartupPath.Length - 10);
con.Close();
//For Progressbar
DataTable dt = new DataTable();
// SqlDataAdapter da = new SqlDataAdapter(cmd);
// da.Fill(dt);
timer5.Enabled = true;
// FOR FtpServer File Upload::
string uploadfile = fileobj.FileName;
string uploadFileName = new FileInfo(uploadfile).Name;
string uploadUrl = "ftp://ftp.infotech.com/";
FileStream fs = new FileStream(uploadfile, FileMode.Open, FileAccess.Read);
try
{
long FileSize = new FileInfo(uploadfile).Length; // File size of file being uploaded.
Byte[] buffer = new Byte[FileSize];
fs.Read(buffer, 0, buffer.Length);
fs.Close();
fs = null;
string ftpUrl = string.Format("{0}/{1}", uploadUrl, uploadFileName);
FtpWebRequest requestObj = FtpWebRequest.Create(ftpUrl) as FtpWebRequest;
requestObj.Method = WebRequestMethods.Ftp.UploadFile;
requestObj.Credentials = new NetworkCredential("test@sample.com", "test@123");
Stream requestStream = requestObj.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
requestObj = null;
}
catch (Exception ex)
{
//MessageBox.Show("File upload/transfer Failed.\r\nError Message:\r\n" + ex.Message, "Succeeded", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
}