Monday, July 13, 2009

I need to display all images in a directory using asp?

I am letting a friend upload his pics into a directory and I need to diplay all of the images in that directory as a gallery. I don't know the file names and I don't know how many will be in the directory. Using asp how do I load all of the images?

I need to display all images in a directory using asp?
I don't use ASP, but it should be as simple as iterating through each of the filenames in the directory and individually displaying them.





Edit:


See JON B's response.
Reply:Here's some code for a server-side button control named "button1" that will display the images, but without any fancy layout. You can add layout commands as needed. Note that this code is pretty basic -- at the least, I suggest changing the hard-coded path to the album to a relative path for more flexibility.





I've copied this from lab #6.1 that I wrote from the BIS-440 class that I occasionally teach for DeVry University:





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click


Dim di As New IO.DirectoryInfo("C:\inetpub\wwwroot\alb...


Dim diar1 As IO.FileInfo() = di.GetFiles("*.jpg")


Dim dra As IO.FileInfo





'list the names of all files in the specified directory


For Each dra In diar1


Response.Write("%26lt;p%26gt; %26lt;img src='../album/")


Response.Write(dra)


Response.Write("' width=100 /%26gt;%26lt;/p%26gt;")


Next


End Sub
Reply:you cant do that


No comments:

Post a Comment