protected void Upload(object sender, EventArgs e)
{
string filename = [Link]([Link]);
string contentType = [Link];
using (Stream fs = [Link])
{
using (BinaryReader br = new BinaryReader(fs))
{
byte[] bytes = [Link]((Int32)[Link]);
string constr = [Link]["connectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
string query = "insert into tblFiles1 values (@Name, @ContentType, @Data, @ModCode, @ModTitle, @ModLecturer,
@Downloads)";
using (SqlCommand cmd = new SqlCommand(query))
{
[Link] = con;
[Link]("@Name", filename);
[Link]("@ContentType", contentType);
[Link]("@Data", bytes);
[Link]("@ModCode", [Link]);
[Link]("@ModTitle", [Link]);
[Link]("@ModLecturer", [Link]);
[Link]("@Downloads", [Link]);
[Link]();
[Link]();
[Link]();
}
}
}
}
[Link]([Link]);
}
protected void DownloadFile(object sender, EventArgs e)
{
int id = [Link]((sender as LinkButton).CommandArgument);
byte[] bytes;
string fileName, contentType, counter;
string constr = [Link]["connectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand())
{
[Link] = "select Name, Data, ContentType, ModCode, ModTitle, ModLecturer, Downloads from tblFiles1 where
id=@id";
[Link]("@id", id);
[Link] = con;
[Link]();
using (SqlDataReader sdr = [Link]())
{
[Link]();
bytes = (byte[])sdr["Data"];
contentType = sdr["ContentType"].ToString();
fileName = sdr["Name"].ToString();
counter = sdr["Downloads"].ToString();
}
[Link]();
[Link]();
int counter1 = Convert.ToInt32(counter);
counter1++;
string strCount = [Link](counter1);
SqlCommand cmd2 = new SqlCommand("UPDATE tblFiles1 SET Downloads = '"+ strCount +"' where id=@id", con);
[Link]("@id", id);
SqlDataReader rd2 = [Link]();
[Link]();
}
}
[Link]();
[Link] = true;
[Link] = "";
[Link]([Link]);
[Link] = contentType;
[Link]("Content-Disposition", "attachment; filename=" + fileName);
[Link](bytes);
[Link]();
[Link]();
}