Click here to Skip to main content
15,899,634 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Try
If ext = "png" OrElse ext = "jpg" OrElse ext = "jpeg" OrElse ext = "PNG" OrElse ext = "JPG" OrElse ext = "JPEG" OrElse ext = "gif" OrElse ext = "GIF" Then
Dim fs As Stream = txtDBImage//error(Unable to cast object of type 'System.String' to type 'System.IO.Stream')
Dim br As BinaryReader = New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CType(fs.Length, Int32))
Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)

Else
Response.Write("alert('unsupported format of photo file');")
End If

Catch ex As Exception
Response.Write("alert('" & ex.Message & "');")
End Try

What I have tried:

Try
If ext = "png" OrElse ext = "jpg" OrElse ext = "jpeg" OrElse ext = "PNG" OrElse ext = "JPG" OrElse ext = "JPEG" OrElse ext = "gif" OrElse ext = "GIF" Then
Dim fs As Stream = txtDBImage
Dim br As BinaryReader = New BinaryReader(fs)
Dim bytes As Byte() = br.ReadBytes(CType(fs.Length, Int32))
Dim base64String As String = Convert.ToBase64String(bytes, 0, bytes.Length)

Else
Response.Write("alert('unsupported format of photo file');")
End If

Catch ex As Exception
Response.Write("alert('" & ex.Message & "');")
End Try
Posted
Updated 25-Mar-19 2:17am

1 solution

Dim fs As Stream = txtDBImage//error(Unable to cast object of type 'System.String' to type 'System.IO.Stream')

A string is not be a stream. You should use a FileStream with the appropriate constructor: FileStream Class (System.IO) | Microsoft Docs[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900