namespace VideoGallery { public partial class VideoGallery : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindGrid(); } } private void BindGrid() { string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "select Id, Name from tblVideo"; cmd.Connection = con; con.Open(); DataList1.DataSource = cmd.ExecuteReader(); DataList1.DataBind(); con.Close(); } } } protected void btnUpload_Click(object sender, EventArgs e) { using (BinaryReader br = new BinaryReader(FileUpload1.PostedFile.InputStream)) { byte[] bytes = br.ReadBytes((int)FileUpload1.PostedFile.InputStream.Length); string strConnString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString; using (SqlConnection con = new SqlConnection(strConnString)) { using (SqlCommand cmd = new SqlCommand()) { cmd.CommandText = "insert into [tblVideo](Name, ContentType, Data) values (@Name, @ContentType, @Data)"; cmd.Parameters.AddWithValue("@Name", Path.GetFileName(FileUpload1.PostedFile.FileName)); cmd.Parameters.AddWithValue("@ContentType", "video/mp4"); cmd.Parameters.AddWithValue("@Data", bytes); cmd.Connection = con; con.Open(); cmd.ExecuteNonQuery(); con.Close(); } } } //Response.Redirect(Request.Url.AbsoluteUri); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)