Sub Page_Load(sender as Object, e as EventArgs)
'Get list of images
Dim dirInfo as New DirectoryInfo(Server.MapPath(""))
Dim images() as FileInfo = FilterForImages(dirInfo.GetFiles())
...
Function FilterForImages(images() as FileInfo) as FileInfo()
Dim newImages as New ArrayList(images.Length)
Dim i as Integer
For i = 0 to images.Length - 1
If Path.GetExtension(images(i).Name) = ".jpg" OrElse _
Path.GetExtension(images(i).Name) = ".jpeg" OrElse _
Path.GetExtension(images(i).Name) = ".png" OrElse _
Path.GetExtension(images(i).Name) = ".gif" then
newImages.Add(images(i))
End If
Next
Return CType(newImages.ToArray(GetType(FileInfo)), FileInfo())
End Function
Sub Page_Load(sender as Object, e as EventArgs)
...
' Dim imgIndex as Integer = 0
If Not Request.QueryString("N") is Nothing AndAlso _
IsNumeric(Request.QueryString("N")) then
imgIndex = CInt(Request.QueryString("N"))
End If
currentImgTitle.Text = "You are Viewing: " & _
Path.GetFileNameWithoutExtension(images(imgIndex).Name) & _
" (" & imgIndex + 1 & " of " & images.Length & ")"
currentImg.ImageUrl = Path.GetFileName(images(imgIndex).Name)
...
End Sub
Sub Page_Load(sender as Object, e as EventArgs)
...
dlIndex.DataSource = images
dlIndex.DataBind()
End Sub
Sub dlIndex_ItemDataBound(sender as Object, e as DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse _
e.Item.ItemType = ListItemType.AlternatingItem then
'Get the Hyperlink
Dim hl as HyperLink = CType(e.Item.FindControl("lnkPic"), HyperLink)
'Set the Text and Navigation properties
hl.Text = Path.GetFileNameWithoutExtension(_
DataBinder.Eval(e.Item.DataItem, "Name").ToString()) & _
" (" & _
Int(DataBinder.Eval(e.Item.DataItem, "Length") / 1000) & _
" KB)"
hl.NavigateUrl = "Default.aspx?N=" & e.Item.ItemIndex
End If
End Sub
<%@ Import Namespace="System.IO" %>
<script runat="server" language="VB">
Sub Page_Load(sender as Object, e as EventArgs)
Dim dirInfo as New DirectoryInfo(Server.MapPath(""))
Dim images() as FileInfo = FilterForImages(dirInfo.GetFiles())
Dim imgIndex as Integer = 0
If Not Request.QueryString("N") is Nothing AndAlso IsNumeric(Request.QueryString("N")) then
imgIndex = CInt(Request.QueryString("N"))
End If
If imgIndex > 0 then
lnkPrev.NavigateUrl = "Default.aspx?N=" & imgIndex - 1
End If
If imgIndex < images.Length - 1 then
lnkNext.NavigateUrl = "Default.aspx?N=" & imgIndex + 1
End If
dlIndex.DataSource = images
dlIndex.DataBind()
End Sub
Function FilterForImages(images() as FileInfo) as FileInfo()
Dim newImages as New ArrayList(images.Length)
Dim i as Integer
For i = 0 to images.Length - 1
If Path.GetExtension(images(i).Name) = ".jpg" OrElse _
Path.GetExtension(images(i).Name) = ".jpeg" OrElse _
Path.GetExtension(images(i).Name) = ".png" OrElse _
Path.GetExtension(images(i).Name) = ".gif" then
newImages.Add(images(i))
End If
Next
Return CType(newImages.ToArray(GetType(FileInfo)), FileInfo())
End Function
Sub dlIndex_ItemDataBound(sender as Object, e as DataListItemEventArgs)
If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType = ListItemType.AlternatingItem then
Dim hl as HyperLink = CType(e.Item.FindControl("lnkPic"), HyperLink)
hl.Text = Path.GetFileNameWithoutExtension(DataBinder.Eval(e.Item.DataItem, "Name").ToString()) & _
" (" & Int(DataBinder.Eval(e.Item.DataItem, "Length") / 1000) & " KB)"
hl.NavigateUrl = "Default.aspx?N=" & e.Item.ItemIndex
End If
End Sub
</script>