I'm trying to use the AsyncUpload (also tried RadUpload w/ the same results) to upload image files and save them in an image field in SQL (not save the file to the filesystem) and then use RadBinaryImage to display them. I get the uploadedfiles collection and loop through it. If I use the saveas method, it works fine. If I use the inputstream (to do anything), I don't get the results I expected... It does write data to the SQL field, but it's not usable... either by RadBinaryImage, or streaming it back to a file... will not open. I also tried skipping the SQL field (for testing) and writing the inputstream directly to the filesystem and the resulting file will not open either. Code for this is below (it's mostly pilfered from Telerik examples...), the commented portion is skipping the DB and writing to file.
If possible, could you post an example using the inputstream (or whatever method is best) to save an image to SQL and then display it using RadBinaryImage.
Thanks
If possible, could you post an example using the inputstream (or whatever method is best) to save an image to SQL and then display it using RadBinaryImage.
Thanks
Private Sub RadAsyncUpload1_FileUploaded(ByVal sender As Object, ByVal e As Telerik.Web.UI.FileUploadedEventArgs) Handles RadAsyncUpload1.FileUploaded |
objCon = New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("HDSWebConnectionString").ConnectionString) |
objCon.Open() |
For Each file As UploadedFile In RadUpload1.UploadedFiles |
Dim bytes(file.InputStream.Length - 1) As Byte |
file.InputStream.Read(bytes, 0, file.InputStream.Length) |
Try |
Dim command As New SqlCommand("insert into Images (Description,ImageData,ImagePath,Caption ) " & _ |
"values ('','@Content','',''); SELECT @@IDENTITY", objCon) |
command.Parameters.AddWithValue("@Content", bytes) |
command.ExecuteNonQuery() |
Finally |
End Try |
Next |
'objCon = New SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("HDSWebConnectionString").ConnectionString) |
'objCon.Open() |
'For Each file As UploadedFile In RadAsyncUpload1.UploadedFiles |
' Dim bytes(file.InputStream.Length - 1) As Byte |
' file.InputStream.Read(bytes, 0, file.InputStream.Length) |
' Try |
' Dim strfn As String = "C:\Users\jcrumpton\Documents\Test.jpg" |
' Dim fs As New FileStream(strfn, FileMode.CreateNew, FileAccess.Write) |
' fs.Write(bytes, 0, file.InputStream.Length) |
' fs.Flush() |
' fs.Close() |
' Finally |
' End Try |
'Next |
End Sub |