'Visit http://www.laptrinhdotnet.com for more ASP.NET Tutorials
Imports System.IO
Namespace jQueryLightboxDatalist
Public Class _Default
Inherits System.Web.UI.Page
#Region "Private Members"
Private FilePath As String = ""
#End Region
#Region "Private Methods"
Private SubSetFilePath()
FilePath = MapPath("~/Images")
If Not Directory.Exists(FilePath) Then
Directory.CreateDirectory(FilePath)
End If
End Sub
Private FunctionGetFullyQualifiedFolderPath(ByVal folderPath As String) As String
If folderPath.StartsWith("~") Then
Return Server.MapPath(folderPath)
Else
Return folderPath
End If
End Function
#End Region
#Region "Bind Data"
Private SubBindData()
Dim currentDirInfo AsNew DirectoryInfo(GetFullyQualifiedFolderPath(FilePath))
Dim folders = currentDirInfo.GetDirectories()
Dim files = currentDirInfo.GetFiles()
Dim fsItems As New List(Of FileSystemItem)(folders.Length + files.Length)
For Each file In files
fsItems.Add(NewFileSystemItem(file))
Next
lstEmployees.DataSource = fsItems
lstEmployees.DataBind()
End Sub
#End Region
#Region "Datalist Methods"
Private SublstEmployees_ItemDataBound(ByVal sender As Object, ByVal e As DataListItemEventArgs) HandleslstEmployees.ItemDataBound
If (e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem) Then
Dim item AsFileSystemItem = CType(e.Item.DataItem, FileSystemItem)
Dim lnkEmployee AsHyperLink = DirectCast(e.Item.FindControl("lnkEmployee"), HyperLink)
If NotlnkEmployee Is NothingThen
lnkEmployee.NavigateUrl = Page.ResolveUrl("Images/"& item.Name)
Dim imgEmployee AsImage = DirectCast(lnkEmployee.FindControl("imgEmployee"), Image)
If NotimgEmployee Is NothingThen
imgEmployee.ImageUrl = Page.ResolveUrl("Images/" & item.Name)
End If
End If
End If
End Sub
#End Region
#Region "Event Handles"
Protected SubPage_Load(ByVal sender AsObject, ByVal e As System.EventArgs) Handles Me.Load
Try
IfPage.IsPostBack = False Then
SetFilePath()
BindData()
End If
Catch ex As Exception
End Try
End Sub
#End Region
End Class
End Namespace