protected void onUpload(object sender, EventArgs e)
{
try
{
string connectionstring = Convert.ToString(ConfigurationManager.ConnectionStrings["NewConnection"]);
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand("Insert into filesupload(FileNames,FilePath) values(@FileName,@FilePath)", con);
string fileName = txtFileName.Text.Trim() + Path.GetExtension(fileupload.FileName);
string FilePath = "~/Files/" + fileName;
fileupload.PostedFile.SaveAs(Server.MapPath("~/Files/" + fileName));
cmd.Parameters.AddWithValue("@FileName", fileName);
cmd.Parameters.AddWithValue("@FilePath", FilePath);
con.Open();
cmd.ExecuteNonQuery();
lblMessage.Text = "Successfully file Uploaded";
this.GetFile();
}
catch (Exception ex)
{
throw;
}
}
private void GetFile()
{
string connectionstring = Convert.ToString(ConfigurationManager.ConnectionStrings["NewConnection"]);
SqlConnection con = new SqlConnection(connectionstring);
SqlCommand cmd = new SqlCommand("Select * from filesupload", con);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);
gvImageView.DataSource = dt;
gvImageView.DataBind();
}