Hi,
Maybe you can use this sample that I once made how you can do it. This uses
images in a database, you can as well choise for using paths. Where in my
opinion this one is better for securing your images.
However, when you store your paths in the database, the images can come from
everywhere. (That is a different and easier solution by the way)
\\\For the database the standard Northwind sample database.
\\\It needs 2 forms with a listbox, a picturebox and a label on form1
\\\webform1
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
Dim conn As New SqlClient.SqlCo nnection _
("Server=(Local ); DataBase=Northw ind;" & _
"Integrated Security=SSPI")
Dim da As New SqlClient.SqlDa taAdapter _
("SELECT FirstName, EmployeeID FROM Employees", conn)
Dim ds As New DataSet
Me.Image1.Visib le = False
ListBox1.AutoPo stBack = True
Try
da.Fill(ds)
ListBox1.DataSo urce = ds.Tables(0)
ListBox1.DataTe xtField = "FirstName"
ListBox1.DataVa lueField = "EmployeeID "
ListBox1.DataBi nd()
Catch sqlExc As SqlClient.SqlEx ception
Me.Label1.Text = sqlExc.ToString
Catch exc As Exception
Me.Label1.Text = exc.ToString
End Try
End If
End Sub
Private Sub ListBox1_Select edIndexChanged( ByVal sender _
As System.Object, ByVal e As System.EventArg s) _
Handles ListBox1.Select edIndexChanged
Session.Item("i mg") = ListBox1.Select edItem.Value
Image1.Visible = True
Image1.ImageUrl = "http://localhost/TestWebImage/WebForm2.aspx"
'This is the location of the aspx files
End Sub
///
\\\webform2 watch that the Memstream, which is for Northwind
'the normal code is as well in it.
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
Dim conn As New SqlClient.SqlCo nnection("Serve r=(Local);" & _
"DataBase=North wind; Integrated Security=SSPI")
Dim sqlstr As String = _
String.Format(" SELECT Photo FROM Employees WHERE (EmployeeID =
{0})", _
CInt(Session.It em("img")))
Dim cmd As New SqlClient.SqlCo mmand(sqlstr, conn)
conn.Open()
Dim rdr As SqlClient.SqlDa taReader = cmd.ExecuteRead er()
rdr.Read()
Dim arrImage() As Byte = DirectCast(rdr. Item("Photo"), Byte())
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''
'Dim ms1 As New System.IO.Memor yStream(arrImag e)
'The one above is for normal purpose, however Northwint has a
strange format
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' '''''''''
Dim ms1 As New System.IO.Memor yStream(arrImag e, 78,
arrImage.Length - 78)
''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''''' ''''''''''''
Dim origimage As System.drawing. Image =
System.Drawing. Image.FromStrea m(ms1)
Dim PThumbnail As System.drawing. Image
PThumbnail = origimage.GetTh umbnailImage(10 0, 100, Nothing, New
IntPtr)
Dim ms2 As New System.IO.Memor yStream
PThumbnail.Save (ms2, Imaging.ImageFo rmat.Bmp)
arrImage = ms2.GetBuffer
Response.Binary Write(arrImage)
rdr.Close()
conn.Close()
End Sub
///
I hope this helps,
Cor