有没有办法使用C1Upload将图像保存到数据库。我只使用Asp.Net,C#.Net进行编程和需要的Javascript,没有别的。有没有一种方法可以在不使用Silverlight的情况下进行保存?
由于
-Mush
答案 0 :(得分:0)
您可以通过在C1Upload1_Uploaded
事件中读取上传文件的字节来完成此操作。
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();
}