How to avoid exceptions when building a file explorer

  • Thread starter Thread starter aaaron123
  • Start date Start date
A

aaaron123

Guest
Private Sub AddDummyNodeMaybe(treeNodes As TreeNodeCollection, dirPath As String)
'The FixedIndex internal property is set to the value of childCount. This is really the index of the last node in the collection.
Try
If treeNodes.Count = 0 AndAlso (IO.Directory.GetDirectories(dirPath).Length > 0 _
OrElse (mAllowFilesDisplay And (IO.Directory.GetFiles(dirPath).Length > 0))) Then
Dim subNode As TreeNode = treeNodes.Add(DUMMY_TITLE)
subNode.Tag = DUMMY_TAG 'If currentFolder not empty and a dummy node has not been already added, add a dummy node
End If
'If it is not accessible I don't want a dummy node anyway
Catch ex As System.UnauthorizedAccessException
Debug.WriteLine("Catch In AddDummyNodeMaybe " & ex.Message)
Catch ex As Exception
Debug.WriteLine("Catch In AddDummyNodeMaybe " & ex.Message)
End Try
End Sub


I call the above when building a tree for a file explorer.

It works OK but I'd like to avoid all the Denied Access exceptions I get.

Can you tell me how to do that?

I don't know what to check that won't cause an exception n the check itself

Continue reading...
 
Back
Top