Giusto .. cerchiamo di liberarci
Con questa sub leggo le sottocartelle :
Public Sub ottieniSottoCartelle(ByVal path As String, ByVal node As TreeNode)
Dim cartelle As String() = IO.Directory.GetDirectories(path)
If cartelle.Length <> 0 Then
Dim cartella As String
For Each cartella In cartelle
Dim newNode As New TreeNode(cartella.Substring((cartella.LastIndexOf("\") + 1)))
newNode.ToolTip = cartella
newNode.PopulateOnDemand = True
newNode.Value = cartella
node.ChildNodes.Add(newNode)
node.SelectAction = TreeNodeSelectAction.SelectExpand
newNode.CollapseAll()
Next cartella
ottieniFiles(path, node)
Else
ottieniFiles(path, node)
End If
End Sub
Con questa Sub leggo i files :
Public Sub ottieniFiles(ByVal path1 As String, ByVal node As TreeNode)
Dim files As String() = IO.Directory.GetFiles(path1)
If files.Length = 0 And node.ChildNodes.Count = 0 Then
Dim newNode1 As New TreeNode("Directory vuota")
newNode1.ToolTip = "Directory vuota"
newNode1.Value = "Directory vuota"
newNode1.NavigateUrl = ""
node.ChildNodes.Add(newNode1)
Else
Dim file As String
For Each file In files
Dim newNode1 As New TreeNode(file.Substring((path1.Length + 1)))
' ricavo l'estensione del file
' due metodi. Ho scelto quello più omogeneo con il resto del progetto
' ma funzionano anche le due righe sotto
'Dim fi As New System.IO.FileInfo(file)
'Dim sExtension1 As String = fi.Extension
Dim sExtension2 As String = file.Substring(file.LastIndexOf("."))
Dim PercTrim As String
PercTrim = Stuff(file, 1, 11, "\\192.168.1.102\Archidoc$")
'scrivo il nodo
newNode1.ToolTip = PercTrim
newNode1.Value = PercTrim
If Session("Membro") = "ok" Then
newNode1.NavigateUrl = PercTrim
Else
newNode1.NavigateUrl = ""
End If
newNode1.Target = "_blank"
'In base all'estensione del file associo una icona
Select Case sExtension2
Case Is = ".doc"
newNode1.ImageUrl = "~/Main/Images/Office2007/Word.ico"
Case Is = ".xls"
newNode1.ImageUrl = "~/Main/Images/Office2007/Excel.ico"
Case Is = ".ppt"
newNode1.ImageUrl = "~/Main/Images/Office2007/Powerpnt.ico"
Case Is = ".mdb"
newNode1.ImageUrl = "~/Main/Images/Office2007/Access.ico"
Case Is = ".pdf"
newNode1.ImageUrl = "~/Main/Images/Adobe/Acrobat.ico"
Case Is = ".psd"
newNode1.ImageUrl = "~/Main/Images/Adobe/Photoshop.ico"
Case Is = ".zip"
newNode1.ImageUrl = "~/Main/Images/Winzip/Winzip.ico"
Case Is = ".txt"
newNode1.ImageUrl = "~/Main/Images/Txt/Txt.ico"
Case Is = ".jpg"
newNode1.ImageUrl = "~/Main/Images/Jpg/Jpg.ico"
Case Is = ".bat"
newNode1.ImageUrl = "~/Main/Images/Bat/bat.ico"
Case Is = ".dwg"
newNode1.ImageUrl = "~/Main/Images/Autodesk/Autodesk.ico"
Case Else
newNode1.ImageUrl = "~/Main/Images/Sconosciuto/Sconosciuto.ico"
End Select
node.ChildNodes.Add(newNode1)
Next file
End If
End Sub