filtering FolderBrowserDialog?

RobinTibbs

Member
Joined
Nov 8, 2006
Messages
18
Programming Experience
Beginner
had a look round the documentation but can't seem to see a way to 'filter' a folderbrowserdialog (ie ONLY let you select a path if it has a certain file in it) is this possible? many thanks in advance :)
 
No, you would have to write your own dialog. You could use a DriveListbox control and a DirListbox control and it would be really simple to allow OK only for paths that contains files of that pattern, but it was better if you custom made the treeview to draw valid and invalid folders with different font/color or something to show this to user without need for trial and error.

When you need file pattern it is perhaps better to use file dialog with filter?
 
VB.NET:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
klasor.SelectedPath = My.Computer.FileSystem.CurrentDirectory
ListView1.GridLines = True
        ListView1.FullRowSelect = True
        ListView1.LabelEdit = True
        ListView1.AllowColumnReorder = True
        ListView1.BackgroundImageTiled = True
        ListView1.MultiSelect = False

End Sub

Private Sub btKlasor_Click(sender As Object, e As EventArgs) Handles btKlasor.Click
        klasor.Description = "Lütfen Bir Klasör Seçiniz."
        If klasor.ShowDialog = DialogResult.OK Then
            seciliklasor = klasor.SelectedPath
            'Kısa yol eklentisi yaparken, aynı yolun tekrar eklenmemesi için  kontrol yapılıyor
            For x = 0 To ComboBox1.Items.Count - 1
                If ComboBox1.Items(x) = seciliklasor Then
                    ComboBox1.SelectedIndex = ComboBox1.FindString(seciliklasor)
                    GoTo git
                End If
            Next
            ComboBox1.Items.Add(klasor.SelectedPath)
git:
            ComboBox1.Text = ""
            ComboBox1.Text = klasor.SelectedPath

            listele()
        End If

    End Sub
    Private Sub listele()

        Dim dirInfo As DirectoryInfo

        ListView1.Items.Clear()
        ListView2.Items.Clear()
        klasor.SelectedPath = ComboBox1.Text & "\"
        dirInfo = New DirectoryInfo(klasor.SelectedPath)

        Arama_Bar(dirInfo)

        Label4.Text = "Dosya Sayısı :" & ListView1.Items.Count
        Label3.Text = "Bulunan :0"
    End Sub
    Public Function GetMediaDuration(ByVal MediaFile As String)
        Try
            Dim w As New WMPLib.WindowsMediaPlayer
            Dim m As WMPLib.IWMPMedia = w.newMedia(MediaFile)
            w.close()
            Return m.duration
        Catch ex As Exception
            Return 0
        End Try
    End Function

Private Sub Arama_Bar(dirInfo As DirectoryInfo)

        Dim uzantiList As New List(Of String)
        uzantiList.Add("*.mp4")
        uzantiList.Add("*.mkv")
        uzantiList.Add("*.ts")
        uzantiList.Add("*.mp3")
        uzantiList.Add("*.avi")
        uzantiList.Add("*.wmv")
        uzantiList.Add("*.3gp")
        uzantiList.Add("*.wav")
        uzantiList.Add("*.mpa")
        uzantiList.Add("*.mpg")
        uzantiList.Add("*.mov")
        uzantiList.Add("*.m4a")
        uzantiList.Add("*.asf")
        uzantiList.Add("*.vob")


        Dim fileInfo As FileInfo
        Dim exePath As String
        Dim exeIcon As Icon
        Dim ListViewItem As ListViewItem

        For Each uzanti In uzantiList
            For Each fileInfo In dirInfo.GetFiles(uzanti)
                If fileInfo.Extension = String.Empty Then
                Else
                    exePath = fileInfo.FullName
                    exeIcon = Drawing.Icon.ExtractAssociatedIcon(exePath)

                    If ımageList1.Images.ContainsKey(exePath) Then
                    Else
                        ımageList1.Images.Add(exePath, exeIcon)
                    End If

                    Dim olsTarihi As DateTime = fileInfo.CreationTime 'dirInfo.CreationT
                    Dim byteBoyut As Long = fileInfo.Length
                    Dim uzantiler As String = fileInfo.Extension
                    'Dim sure As New MediaInfoNET.MediaInfo_Stream_Video
                    ''-----------------------------'Medya süre(duration) bilgisini alır
                    On Error Resume Next
                    Dim videoDuration As String = TimeSpan.FromSeconds(Math.Round(GetMediaDuration _
                        (ComboBox1.Text & "\" & fileInfo.Name))).ToString ' Format hh:mm:ss
                    ''----------------------------------
                    byteBoyut = (byteBoyut / 1024) / 1000
                    ListView1.LargeImageList = ımageList1
                    ListViewItem = ListView1.Items.Add(fileInfo.Name)
                    ListViewItem.SubItems.Add(byteBoyut.ToString() & "  MB ")
                    ListViewItem.SubItems.Add(olsTarihi.ToString("dd.MM.yyyy"))
                    ListViewItem.SubItems.Add(uzantiler.ToString)
                    ListViewItem.SubItems.Add(videoDuration) 'Medya süre(duration) bilgisini alır(hh:mm:ss)
                    'ListViewItem.SubItems.Add(sure.DurationString)
                    ListViewItem.ImageKey = exePath

                                 End If
            Next
        Next


    End Sub
 
Last edited by a moderator:
medya bul.jpeg
 
Back
Top