Imports System.IO Public Class MediaLister Inherits System.Web.UI.UserControl #Region " Codice generato da Progettazione Web Form " _ Private Sub InitializeComponent() End Sub Protected WithEvents LitFiles As System.Web.UI.WebControls.Literal Protected WithEvents LitPages As System.Web.UI.WebControls.Literal Protected WithEvents LitDirs As System.Web.UI.WebControls.Literal Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Init InitializeComponent() End Sub #End Region Public FirstItem As Boolean = True Private Sub BuildPagers(ByVal ItemsCount As Integer, _ ByVal MaxItems As Integer) Dim i As Integer Dim pages As Integer pages = ItemsCount / MaxItems If (pages * MaxItems) < ItemsCount Then pages += 1 End If LitPages.Text = "
" For i = 0 To pages - 1 LitPages.Text += "" + (i + 1).ToString() + _ " " If (i + 1) Mod 18 = 0 Then LitPages.Text += "
" End If Next End Sub Private Sub ShowItem(ByVal Cat As String, ByVal SubCat As String,_ ByVal fName As String) Dim ext As String Dim fPath As String ext = fName.Substring(fName.LastIndexOf(".") + 1) ext = ext.ToLower() Select Case ext Case "jpg", "bmp", "gif" ' LitFiles.Text += _ "" fPath = "pub/Lib/" + Cat + "/" + _ SubCat + "/" + fName If FirstItem Then FirstItem = False LitFiles.Text += "" End If LitFiles.Text += _ "" Case "wav", "mid", "mp3" LitFiles.Text += _ "" Case "avi", "mpg", "wmv" LitFiles.Text += _ "" End Select End Sub Private Sub LoadDirList(ByVal Cat As String, _ ByVal SubCat As String) Dim tmpfile As String Dim tmpName As String Dim i As Integer Dim k As Integer Dim MaxCols As Integer = 4 Dim MaxRows As Integer = 3 Dim MaxItems = MaxCols * MaxRows Dim ItemsCount = 0 Dim CurCol = 0 Dim StartIndex As Integer tmpfile = Server.MapPath("/") + "pub\Lib\" + _ Cat + "\" + SubCat Dim files() As String = Directory.GetDirectories(tmpfile) If files.Length > 0 Then LitDirs.Text += _ "" CurCol = 0 For i = 0 To files.Length - 1 tmpName = files(i).ToString() tmpName = tmpName.Substring(tmpName.LastIndexOf("\")+1) tmpName = tmpName.Replace(" ", "%20") CurCol += 1 If CurCol > MaxCols Then LitDirs.Text += "" CurCol = 1 End If LitDirs.Text += _ "" Next For i = CurCol To MaxCols LitDirs.Text += "" Next LitDirs.Text += "

"+_ tmpName.Replace("%20", " ") + "
 
" End If End Sub Private Sub LoadFileList(ByVal Cat As String,_ ByVal SubCat As String,ByVal StartPage As Integer) Dim tmpfile As String Dim tmpName As String Dim i As Integer Dim MaxCols As Integer = 6 Dim MaxRows As Integer = 1 Dim MaxItems = MaxCols * MaxRows Dim ItemsCount = 0 Dim CurCol = 0 Dim StartIndex As Integer If StartPage = 0 Then LoadDirList(Cat, SubCat) End If tmpfile = Server.MapPath("/") + "pub\Lib\" + Cat + "\" + SubCat Dim files() As String = Directory.GetFiles(tmpfile) If files.Length > 0 Then If SubCat.LastIndexOf("\") > 0 Then LitFiles.Text = "
" + Cat + _ " (" + _ SubCat.Substring(SubCat.LastIndexOf("\") + 1) + _ ")
" Else LitFiles.Text = "
" + Cat + _ " (" + SubCat + _ ")
" End If BuildPagers(files.Length, MaxItems) i = StartPage * MaxItems StartIndex = i LitFiles.Text += _ "" CurCol = 0 While (i < (StartIndex + MaxItems) _ And i <= (files.Length() - 1)) tmpName = files(i).ToString() tmpName = tmpName.Substring(tmpName.LastIndexOf("\")+1) tmpName = tmpName.Replace(" ", "%20") i += 1 CurCol += 1 If CurCol > MaxCols Then LitFiles.Text += "" CurCol = 1 End If ShowItem(Cat, SubCat, tmpName) End While For i = CurCol To MaxCols LitFiles.Text += "" Next LitFiles.Text += "
 
" LitPages.Text += "

Sei a Pagina. " + _ (StartPage + 1).ToString() + "
" End If End Sub Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load FirstItem = True If Not Page.IsPostBack Then LoadFileList(Request("Cat"), Request("SCat"),_ Request("Page")) End If End Sub End Class