How can i display an image in an ImageBox in ASP.NET

zoul1380
03-28-2007, 08:23 AM
How can i display an image which is specified in my PC in an IMAGEBOX in ASP.NET here is my code.

Assume that there is 10 Jpg File in my specified Directory.

Please Help Me thanks.. im just a newbie :) on ASP.NET


Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Page.IsPostBack = False Then
GetFiles()
End If
End Sub

Private Sub GetFiles()

Dim JPGFile() As String = System.IO.Directory.GetFiles("C:\Documents and Settings\rom\My Documents\My Pictures\Test", "*.jpg")
Dim x As Integer

For x = LBound(JPGFile) To UBound(JPGFile)
Response.Write(JPGFile(x) & "<BR>")
Next

Image1.ImageUrl = JPGFile(1).ToString

End Sub

wayneph
03-28-2007, 09:30 AM
What I'd do is create a panel on your page. Then in your loop create an instance of the Image object and set the ImageURL property to the file name. Then you can add it to the control array of the panel.

That being said, if you're going to be running this from a remote computer, you can't use images from the Documents and Settings folder. You need to make sure that it's available in a web share. Most of the time it's set up in c:\Inetpub\wwwroot\.

MKoslof
03-30-2007, 10:09 AM
Can you store the images in a relative server directory and then provide access to this virtual folder in your web config, i.e:


<location path="Images">
<system.web>
<authorization>
<allow users="*" />
</authorization>
</system.web>
</location>

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum