none
DirectorySearcher RRS feed

  • Question

  • Hi there.  

    I am atemting to finalize the virtual recipe book for my wife.  The main directory for the recipes is located on my  PC, I prefer toKeep it like that.  

    This means that the line  RecipeFolder = "M:\My Documents\My Resepte" will have to be changed to enabel my wife to find the directory over the network, so I thought of using a DirectorySearcher and then saving the selected directory to Settings.  

    Can you please explane to me step by step how to do this.

    Sunday, March 15, 2020 7:26 AM

Answers

  • Something like this, with a string Settings named MainDirectory :
    Dim sMainFolder As String = My.Settings.MainDirectory
    Dim fbd As New FolderBrowserDialog
    If IO.Directory.Exists(sMainFolder) Then
        fbd.SelectedPath = sMainFolder
    End If
    If fbd.ShowDialog = DialogResult.OK Then
        sMainFolder = fbd.SelectedPath
        My.Settings.MainDirectory = sMainFolder
        My.Settings.Save()
        MsgBox("Recipe Folder Saved")
    End If



    Sunday, March 15, 2020 8:54 AM

All replies

  • I thought of using a DirectorySearcher and then saving the selected directory to Settings.  

    FolderBrowserDialog Class ?

    • Edited by Castorix31 Sunday, March 15, 2020 7:39 AM
    Sunday, March 15, 2020 7:37 AM
  • I thought of using a DirectorySearcher and then saving the selected directory to Settings.  

    FolderBrowserDialog Class ?

    My mistake, thanks.
    Sunday, March 15, 2020 7:46 AM
  • This is what I have so far.  

     Private Sub SettingsLabel_Click(sender As Object, e As EventArgs) Handles SettingsLabel.Click
    
            Dim result As DialogResult
            result = FolderBrowserDialog.ShowDialog
    
            If result = Windows.Forms.DialogResult.OK Then
                MsgBox("Recipe Folder Saved")
            End If
    
        End Sub
    Now for step 2, How do I go about saving the selected folder to Settings?

    Sunday, March 15, 2020 8:20 AM
  • Something like this, with a string Settings named MainDirectory :
    Dim sMainFolder As String = My.Settings.MainDirectory
    Dim fbd As New FolderBrowserDialog
    If IO.Directory.Exists(sMainFolder) Then
        fbd.SelectedPath = sMainFolder
    End If
    If fbd.ShowDialog = DialogResult.OK Then
        sMainFolder = fbd.SelectedPath
        My.Settings.MainDirectory = sMainFolder
        My.Settings.Save()
        MsgBox("Recipe Folder Saved")
    End If



    Sunday, March 15, 2020 8:54 AM
  • Hendrik,

    While almost all controls in VB are simply in the Win32 area has the folderdialogsearcher always been a quick and dirty piece which came with VB 7.1 because the likewise control from VB 6.0 was not available in .Net. 

    The last used folder is automatically set in the registry and used the next time and that is it. You've to live with that. 

    (Probably the reason that some use the build in filebrowserdialog instead of that but that has again other trouble for that sake)


    Success
    Cor

    Sunday, March 15, 2020 7:05 PM
  • Hi,

    Have you solved this problem now?

    I think the above reply can provide you with a solution, have you tried it?

    If so, hope you can close this thread by marking the reply as answer as this will help others looking for the same or similar issues down the road.

    By the way, since you think the operation steps are a bit complicated, why don't you choose to use a SaveFileDialog to select the location to save the file when saving, and then use Path.GetDirectoryName () to remember the saved address? I think it will be more convenient.

    If you have anything else about this issue, please feel free to contact us.

    Best Regards,

    Julie


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.



    Monday, March 16, 2020 2:56 AM
    Moderator
  • Here is what I have tried so fur.

     Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
    
            Dim result As DialogResult
            result = FolderBrowserDialog.ShowDialog
    
            Dim SelectedFolder As String = My.Settings.MyRecipeFolder
            Dim fbd As New FolderBrowserDialog
    
            If IO.Directory.Exists(SelectedFolder) Then
                fbd.SelectedPath = SelectedFolder
            End If
    
            If fbd.ShowDialog = DialogResult.OK Then
                SelectedFolder = fbd.SelectedPath
                My.Settings.MyRecipeFolder = SelectedFolder
                My.Settings.Save()
               
            End If
    
            Me.Label2.Text = My.Settings.MyRecipeFolder.ToString
    
        End Sub

    Firstly my problem with this is when cliecking OK FolderBrowserDialog it does not close, it only closes on a 2nd click.  

    2ndly I am using Label2 to atemt viewing the string saved to settings.  It allwais turns out to be  C:\Users\Hendri\Desktop no matter what address I atempt to use.

    Tuesday, March 17, 2020 3:25 PM
  • Firstly my problem with this is when cliecking OK FolderBrowserDialog it does not close, it only closes on a 2nd click.  


    Read the code I posted...

    You call ShowDialog twice !


    • Edited by Castorix31 Tuesday, March 17, 2020 3:42 PM
    Tuesday, March 17, 2020 3:42 PM