protected void
btnSave_Click(object sender, EventArgs e)
{
string fname =
Path.GetFileName(flupUpload.PostedFile.FileName.ToString());
string ext =
Path.GetExtension(fname); // to get
extension of file
if (flupUpload.HasFile)
{
flupUpload.SaveAs(Server.MapPath("fileCollection/"
+ fname));
string ins
= "insert into tbl_upload(file_caption,file_name)values('" +
txtcaption.Text + "','" + fname + "')";
obj.execute_Query(ins);
}
}
protected void btnShow_Click(object sender,
EventArgs e)
{
string sel = "select * from
tbl_upload";
obj.fillGrid(grdFiles, sel);
}
protected void grdFiles_RowCommand(object
sender, GridViewCommandEventArgs e)
{
if (e.CommandName ==
"download")
{
int id =
Convert.ToInt32(e.CommandArgument.ToString());
string str = "select * from
tbl_upload where file_id=" + id + "";
DataTable dt = new DataTable();
dt = obj.select_Query(str);
if (dt.Rows.Count > 0)
{
string name =
dt.Rows[0]["file_name"].ToString();
filedownload(name);
}
}
}
protected void filedownload(string
name)
{
Response.AppendHeader("content-disposition","attachment;filename="
+ name + "");
Response.TransmitFile(Server.MapPath("fileCollection/" +
name));
Response.End();
}
}
No comments:
Post a Comment