// Read the file and convert it to Byte Array string filePath = FileUpload2.PostedFile.FileName; string filename = Path.GetFileName(filePath); string ext = Path.GetExtension(filename); string contenttype = String.Empty; //Set the contenttype based on File Extension switch (ext) { case ".doc": contenttype = "application/vnd.ms-word"; break; case ".docx": contenttype = "application/vnd.ms-word"; break; case ".pdf": contenttype = "application/vnd.ms-word"; break; } if (contenttype != String.Empty) { Stream fs = FileUpload1.PostedFile.InputStream; BinaryReader br = new BinaryReader(fs); Byte[] bytes = br.ReadBytes((Int32)fs.Length); //insert the file into database string strQuery = "insert into PARTY(Party_Manifesto)" + " values (@Party_Manifesto)"; SqlCommand cmd = new SqlCommand(strQuery); //cmd.Parameters.Add("@Candidate_Image", SqlDbType.VarChar).Value = filename; //cmd.Parameters.Add("@ContentType", SqlDbType.VarChar).Value // = contenttype; cmd.Parameters.Add("@Party_Manifesto", SqlDbType.Binary).Value = bytes; InsertUpdateData(cmd); lblmsg.ForeColor = System.Drawing.Color.Green; lblmsg.Text = "File Uploaded Successfully"; } else { lblmsg.ForeColor = System.Drawing.Color.Red; lblmsg.Text = "File format not recognised." + " Upload document/pdf/doc/docs formats"; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)