Click here to Skip to main content
15,171,576 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i used the following code for uploading and inserting video into mysql database but does not run .. can anyone help me ??

public class FileUploadController : Controller
        // GET: /FileUpload/

        string strcon = "server=ASMAA-PC;database=SignLanguage;integrated security=true";
        public ActionResult FileUpload(HttpPostedFileBase FileUpload1)
            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(strcon))
                    using (SqlCommand cmd = new SqlCommand())
                        cmd.CommandText = "insert into tblFiles(Video_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;

            return View();

1 solution

cmd.Parameters.AddWithValue("@Name", Path.GetFileName(FileUpload1.PostedFile.FileName));
You are just storing the name of the file here. You need to convert the image into bytes and store it in the database.

Member 9702410 9-Jun-13 14:47pm
i already used the following code , but i want to use this with MVC3 ASP.NET

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900