Question:
I need to display all images in a directory using asp?
anonymous
2006-12-31 09:43:29 UTC
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?
Three answers:
Chris
2006-12-31 10:40:00 UTC
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.
JON B
2006-12-31 18:38:44 UTC
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\album\")

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("

")

Next

End Sub
sudandragon
2006-12-31 17:51:02 UTC
you cant do that


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...