i want to make an application, where user can upload their images and display it in Image control without physically saving it in a folder on disk. after done build the cone, an error show on this line.

Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)

Error show on the attachment below.

Here my full code :

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim fs As System.IO.Stream = FileUpload1.PostedFile.InputStream
        Dim br As New System.IO.BinaryReader(fs)
        Dim bytes As Byte = br.ReadBytes(CType(fs.Length, Integer))
        Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)

        Image1.ImageUrl = "data:image/png;based64," & base64string
        Image1.Visible = True

    End Sub
End Class

Can anyone help me to solve this problem?

Recommended Answers

All 2 Replies

Line 7 you declare bytes as Byte. I think that should be an array of Bytes.

Hi DaveAmour :)

Sorry for my late respond. Yes, your solution works!
I need to change the declaration.

Anyway, thank you for helping me ! :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.