Dear All
I am working on FileUpload Control. By using this control when i select any image that image should be displayed in image button.
How to achieve this can any one help me
Thanks in advance
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Lalit MRank #1,186 · 1.5K reputationPosted Dec 21, 2009, 11:52 PM EST
paul daniel189 reputationPosted Dec 22, 2009, 11:28 PM EST
'#Region "Reading file"
fs = New FileStream(Filename, FileMode.Open)
' Finding out the size of the file to be uploaded
Dim fi As FileInfo = New FileInfo(Filename)
Dim temp As Long = fi.Length
Dim lung As Integer = Convert.ToInt32(temp)
' Reading the content of the file into an array of bytes.
Dim picture As Byte() = New Byte(lung - 1) {}
fs.Read(picture, 0, lung)
fs.Close()
conn = New SqlConnection(ConnectionString)
Dim picstr As New SqlParameter
picstr = insertStatement.Parameters.Add("@picstr",Text)
Dim picstr1 As String
picstr.Value = picture
Dim l As String
l = BitConverter.ToString(picture)
insertStatement.CommandText = "update organization set companyimage=@picstr where organization_id=3"
insertStatement.CommandType = CommandType.Text
l = Replace(l, "-", "")
'insertStatement.CommandText = "insert into imagetbl (imageschk,imageId) values(" & l & ")"
To Retrive the Image
Dim DAdap As New SqlClient.SqlDataAdapter
Dim DS As New DataSet
Dim result As Byte()
conn = New SqlConnection(ConnectionString)
insertStatement.Connection = conn
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
insertStatement.CommandText = "select * from organization "
insertStatement.CommandType = CommandType.Text
DAdap.SelectCommand = insertStatement
DAdap.Fill(DS)
'Dim DS As New DataSet
DAdap.Fill(DS)
result = CType(DS.Tables(0).Rows(0).Item("imageschk"), Byte())
Dim ms As MemoryStream = New MemoryStream(result, 0, result.Length)
Dim im As Image = Image.FromStream(ms)
Picture.Image = im
Its helpful to you