Thank you for viewing the source code to
Pictures.aspx.
If you see any bugs in this code, please
Let me know! I will be
happy to correct the problem.
Partial Class Pictures
Inherits System.Web.UI.Page
Dim RandomClass As New Random()
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.ltRefresh.Text = "<a href=""pictures.aspx?Rand=" & RandomClass.Next().ToString & """>Click here</a> to refresh."
Me.ltRefresh2.Text = "<a href=""pictures.aspx?Rand=" & RandomClass.Next().ToString & """>Click here</a> to refresh."
Dim i As Integer
For i = 1 To 9
' // Show some Random Files
Call ShowRandomFile("")
Next
End Sub
Private Sub ShowRandomFile(ByVal subdir As String)
' // List the contents of the downloads directory
Dim dir As New System.IO.DirectoryInfo(Server.MapPath("Pictures") & "\" & subdir)
Dim dirs As System.IO.DirectoryInfo() = dir.GetDirectories()
If dirs.Count > 0 Then
' // Randomly pick a Sub-Directory...
'Create a new Random class in VB.NET
Dim RandomDir As Integer = RandomClass.Next(0, dirs.Count)
Call ShowRandomFile(subdir & dirs(RandomDir).Name & "\")
Else
' // No Sub-Directories, randomly pic a picture
Dim fils As System.IO.FileInfo() = dir.GetFiles
If fils.Count > 0 Then
Dim RandomFile As Integer = RandomClass.Next(0, fils.Count)
Dim strFile As String = subdir.Replace("\", "/") & fils(RandomFile).Name
If strFile.ToLower.EndsWith(".jpg") OrElse strFile.ToLower.EndsWith(".jpeg") OrElse strFile.ToLower.EndsWith(".gif") OrElse strFile.ToLower.EndsWith(".png") Then
Me.pnlPictures.Controls.Add(New LiteralControl( _
"<img src=""Pictures/" & strFile & """ WIDTH='500' alt=""" & strFile & """/>" & _
"<br/>" & strFile.Replace("\", "/") & "<br/>"))
End If
End If
End If
End Sub
End Class
Copyright © 1984-2024 Dennis Day
All rights reserved