Displaying image from folder/file in vb.net

i want to display image from folder, for example, student with an id number of 22137471, the picture with the name of 22137471 will be display on my picture box

Try something like...

Dim id As String = "22137471"
Dim folder As String = "c:\some path\folder"
Dim filename As String = System.IO.Path.Combine(folder, id & ".png")
PictureBox1.Image = Image.FromFile(filename)

Here's an updated version that doesn't lock the original image file:

Dim id As String = "22137471"
Dim folder As String = "c:\some path\folder"
Dim filename As String = System.IO.Path.Combine(folder, id & ".png")
Try
    Using fs As New System.IO.FileStream(filename, IO.FileMode.Open)
        PictureBox1.Image = New Bitmap(Image.FromStream(fs))
    End Using
Catch ex As Exception
    Dim msg As String = "Filename: " & filename &
        Environment.NewLine & Environment.NewLine &
        "Exception: " & ex.ToString
    MessageBox.Show(msg, "Error Opening Image File")
End Try

Tags:

Vb.Net 2010