Originariamente inviato da cassano
potresti intercettare l'eccezzione generata nel caso la cartella sia protetta.
come sai, nel framework2 hanno aggiunto tante cose, come per esempio TryParse etc... e questo proprio per non appesantire con try-Catch
io ho fatto
codice:
Protected Sub TreeView1_TreeNodePopulate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.TreeNodeEventArgs) Handles TreeView1.TreeNodePopulate
Dim nodo As TreeNode = e.Node
Dim Path As String = nodo.Value
Dim protetta As Boolean = False
Try
Dim tmp As Object = Directory.GetAccessControl(Path)
Catch ex As Exception
protetta = True
End Try
If Not protetta Then
For Each subdir As String In Directory.GetDirectories(Path)
Dim childNode As New TreeNode(IO.Path.GetFileName(subdir), subdir)
childNode.SelectAction = TreeNodeSelectAction.Expand
childNode.PopulateOnDemand = True
childNode.Collapse()
nodo.ChildNodes.Add(childNode)
Next
For Each fname As String In Directory.GetFiles(Path)
Dim childNode As New TreeNode(IO.Path.GetFileName(fname), fname)
childNode.SelectAction = TreeNodeSelectAction.Expand
childNode.Collapse()
nodo.ChildNodes.Add(childNode)
Next
End If
End Sub
ma speravo in qualcosa di meglio. Ciao