Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
317 views
in Technique[技术] by (71.8m points)

treeview - VB.NET 2008 Not recognizing Path.GetFileName Method

I have read this post but nothing works. Visual Basic not recognizing Path.GetFileName Method I am following this page in trying to get the filename in my Visual Basic application but i can't compile it Microsoft Official Page

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    size_mode_list.Items.AddRange([Enum].GetNames(GetType(PictureBoxSizeMode)))


    For Each drive As DriveInfo In DriveInfo.GetDrives
        Dim node As TreeNode = _
            file_view_tree.Nodes.Add(drive.Name)
        node.Tag = ItemType.Drive
        node.Nodes.Add("FILLER")
    Next

End Sub

Private Sub file_view_tree_BeforeExpand(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles file_view_tree.BeforeExpand
    Dim currentNode As TreeNode = e.Node
    currentNode.Nodes.Clear()
    Try
        'Now go get all the files and folders
        Dim fullPathString As String = currentNode.FullPath

        'Handle each folder
        For Each dolderString As String In _
            Directory.GetDirectories(fullPathString)
            Dim newNode As TreeNode = _
                currentNode.Nodes.Add(path.getFileName(folderString))
            Dim x As String = path.GetFileName("")
            newNode.Tag = ItemType.Folder
            newNode.Nodes.Add("FILLER")
        Next

        'Handle each file
        For Each fileString As String In _
            Directory.GetFiles(fullPathString)
            'Get just the file name portion (without the path) :
            Dim newNode As TreeNode = _
                currentNode.Nodes.Add(path.getFileName(fileString))
            newNode.Tag = ItemType.File
        Next
    Catch ex As Exception
    End Try
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
'Don't forget to import this
Imports System.IO

'Declare these
Private Enum ItemType
    Drive
    Folder
    File
End Enum

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    For Each drive As DriveInfo In DriveInfo.GetDrives
        Dim node As TreeNode = _
            file_view_tree.Nodes.Add(drive.Name)
        node.Tag = ItemType.Drive
        node.Nodes.Add("FILLER")
    Next
End Sub

Private Sub file_view_tree_BeforeExpand(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeViewCancelEventArgs) Handles file_view_tree.BeforeExpand
    Dim currentNode As TreeNode = e.Node
    currentNode.Nodes.Clear()
    Try
        'Now go get all the files and folders
        Dim fullPathString As String = currentNode.FullPath

        'Handle each folder
        For Each folderString As String In _
            Directory.GetDirectories(fullPathString)
            Dim newNode As TreeNode = _
            currentNode.Nodes.Add(Path.GetFileName(folderString))
            Dim x As String = Path.GetFileName("")
            newNode.Tag = ItemType.Folder
            newNode.Nodes.Add("FILLER")
        Next

        'Handle each file
        For Each fileString As String In _
            Directory.GetFiles(fullPathString)
            'Get just the file name portion (without the path) :
            Dim newNode As TreeNode = _
            currentNode.Nodes.Add(Path.GetFileName(fileString))
            newNode.Tag = ItemType.File
        Next
    Catch ex As Exception

    End Try
End Sub

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...