Is there a way to save image to the database using C1Upload. I am only using Asp.Net, C#.Net for the programming and Javascr开发者_如何学Cipt of needed and nothing else. Is there a way in saving without using Silverlight?
Thanks
-Mush
You you do this by reading the bytes of uploaded file in C1Upload1_Uploaded
event.
protected void C1Upload1_Uploaded(object sender, UploadedFileEventArgs e)
{
//Read uploaded file stream
C1FileInfo file = e.UploadedFile;
byte[] buffer = new byte[file.Size];
file.GetStream().Read(buffer, 0, file.Size);
file.GetStream().Close();
//Save file bytes to database
System.Data.SqlClient.SqlConnection sqlConn = new System.Data.SqlClient.SqlConnection("sqlConnectionString");
System.Data.SqlClient.SqlCommand sqlCmd = new System.Data.SqlClient.SqlCommand("INSET INTO yourtable(image) VALUES(@image)", sqlConn);
sqlCmd.Parameters.AddWithValue("@image", buffer);
sqlConn.Open();
sqlCmd.ExecuteNonQuery();
sqlConn.Close();
}
精彩评论