Code: Select all
protected void editClick(object sender, EventArgs e)
{
HiddenDocID.Value = (sender as LinkButton).CommandArgument;
ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "open();", true);
}
protected void EditFileUpload(object sender, EventArgs e)
{
string id = HiddenDocID.Value;
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
string contentType = FileUpload1.PostedFile.ContentType;
try
{
using (Stream fs = FileUpload1.PostedFile.InputStream)
{
using (BinaryReader br = new BinaryReader(fs))
{
byte[] bytes = br.ReadBytes((Int32)fs.Length);
string strConString = ConfigurationManager.ConnectionStrings["DatabaseConnection"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConString))
{
string query = @"UPDATE Documents SET Doc_name = @Doc_name, Doc_type = @Doc_type, Data = @Data where [Doc_id] = @Doc_id";
using (SqlCommand cmd = new SqlCommand(query))
{
cmd.Connection = con;
cmd.Parameters.AddWithValue("@Doc_name", filename);
cmd.Parameters.AddWithValue("@Doc_type", contentType);
cmd.Parameters.AddWithValue("@Data", bytes);
cmd.Parameters.AddWithValue("@Doc_id", id);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
}
}
}
catch (Exception ex)
{
string error = ex.Message;
}
}