foreach (HttpPostedFile postedFile in FileUpload2.PostedFiles) { string filename = Path.GetFileName(postedFile.FileName); FileUpload2.SaveAs(Server.MapPath(".") + "//im1//" + filename); string path2 = "~//im1//" + filename.ToString(); string contentType = postedFile.ContentType; using (Stream fs = postedFile.InputStream) { using (BinaryReader br = new BinaryReader(fs)) { byte[] bytes = br.ReadBytes((Int32)fs.Length); string constr =ConfigurationManager.ConnectionStrings["newsConnectionString"].ConnectionString; using (SqlConnection con = new SqlConnection(constr)) { string query = "insert into news(image_name,content_type,data)values(@Name, @ContentType, @Data)"; using (SqlCommand cmd = new SqlCommand(query)) { cmd.Connection = con; cmd.Parameters.AddWithValue("@Name", path2); cmd.Parameters.AddWithValue("@ContentType", contentType); cmd.Parameters.AddWithValue("@Data", bytes); con.Open(); cmd.ExecuteNonQuery(); con.Close(); } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)