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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
paul danielPosted Dec 23, 2009, 4:28 AM
'#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
Lalit MPosted Dec 22, 2009, 4:52 AM