I have a web form with an asp: img control in which I want to show an image, of which I only have the complete path of the file (including the file name) that is stored on the server (the path is saved in a table in the database). But I do not know how to do it. Is there an example of how to do it, for example, embedding vb .net code in the aspx page?
EDIT: SOLVED.
I solved it in the following way:
Function to get the image in base64:
Public Function obtenerImagen(rutaOrden As String) As String
Try
Dim bytesImagen As Byte() = System.IO.File.ReadAllBytes(rutaOrden)
Dim imagenBase64 As String = Convert.ToBase64String(bytesImagen)
Dim tipoContenido As String
Select Case Path.GetExtension(rutaOrden)
Case ".jpg"
tipoContenido = "image/jpg"
Case ".gif"
tipoContenido = "image/gif"
Case ".png"
tipoContenido = "image/png"
Case Else
Return Nothing
End Select
Return String.Format("data:{0};base64,{1}", tipoContenido, imagenBase64)
Catch
Return Nothing
End Try
End Function
And from here I call the function to assign the url to the asp image control:
Dim rutaOrden As String = solicitud("adjunto").ToString.Trim
Dim imagenOrden As String = obtenerImagen(rutaOrden)
If imagenOrden = Nothing Then
imgOrdenMedica.AlternateText = "Error al obtener la imagen de la orden"
lnkOrden.Visible = False
Else
imgOrdenMedica.ImageUrl = imagenOrden
End If