Any controls for Folder selection Not File. When I click "Browse"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vishwa Ram
    New Member
    • May 2007
    • 30

    Any controls for Folder selection Not File. When I click "Browse"

    Hello VB Developers....


    I like to select a folder, by clicking a button.

    I am using common dialog box for this. But it selects only file.

    Also I need code to list of xml file to list into list box contains the selected folder.

    Thanks.
    vishwa Ram.
  • CoMPMStR
    New Member
    • Jun 2007
    • 8

    #2
    You need to be more specific with your help questions. State whether you're using VB6 or .NET, not just what you want to do. It's real easy to do it in .NET:

    Code:
            'set the folder browser
            Dim folderBrowser As New FolderBrowserDialog
    
            'open the dialog and if the user presses OK...
            If folderBrowser.ShowDialog And Windows.Forms.DialogResult.OK Then
    
                'set the directory info for the selected folder
                Dim dirInfo As New System.IO.DirectoryInfo(folderBrowser.SelectedPath)
    
                'clear the listbox
                ListBox1.Items.Clear()
    
                'iterate through the files in the selected folder...
                For i As Integer = 0 To dirInfo.GetFiles.Length - 1
                    'if the extension is xml...
                    If LCase(System.IO.Path.GetExtension(folderBrowser.SelectedPath & "\" & _
                    dirInfo.GetFiles.GetValue(i))) = ".xml" Then
                        'list them in the listbox
                        ListBox1.Items.Add(dirInfo.GetFiles.GetValue(i))
                    End If
                Next
            End If
    I hope that's what you're looking for. Reply if it works or not.

    Comment

    Working...