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()) ... 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 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 |
<ASP:Label runat="server" id="currentImgTitle" /><br /> <asp:Image runat="server" id="currentImg" /> |
Sub Page_Load(sender as Object, e as EventArgs) ... 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 ... End Sub |
<asp:HyperLink runat="server" id="lnkPrev" Text="< Previous" /> | <asp:HyperLink runat="server" id="lnkNext" Text="Next >" /> |
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 |
<asp:DataList runat="server" id="dlIndex" OnItemDataBound="dlIndex_ItemDataBound" RepeatColumns="3"> <ItemTemplate> <li><asp:HyperLink runat="server" id="lnkPic" /></li> </ItemTemplate> </asp:DataList> |
<%@ 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 currentImgTitle.Text = "You are Viewing: " & _ Path.GetFileNameWithoutExtension(images(imgIndex).Name) & _ " (" & imgIndex + 1 & " of " & images.Length & ")" currentImg.ImageUrl = Path.GetFileName(images(imgIndex).Name) 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> <HTML> <HEAD> <STYLE TYPE="text/css"> body { font-family:Verdana;font-size: medium;} .ImageTitle { font-weight:bold; font-size:large;} .index {font-size: small;} .NavLink { background-color: yellow; font-weight: bold; } </STYLE> </HEAD> <BODY> <center> <asp:Label runat="server" id="currentImgTitle" CssClass="ImageTitle" /><br /> <asp:Image runat="server" id="currentImg" /> <asp:HyperLink runat="server" CssClass="NavLink" id="lnkPrev" Text="< Previous" /> | <asp:HyperLink runat="server" CssClass="NavLink" id="lnkNext" Text="Next >" /> <asp:DataList runat="server" id="dlIndex" OnItemDataBound="dlIndex_ItemDataBound" RepeatColumns="3" CssClass="index"> <ItemTemplate> <li><asp:HyperLink runat="server" id="lnkPic" /></li> </ItemTemplate> </asp:DataList> </center> </BODY> </HTML> |