Results 1 to 3 of 3

Thread: [RESOLVED] Search for a folder path and save it as a variable.

  1. #1

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    42

    Resolved [RESOLVED] Search for a folder path and save it as a variable.

    I wrote a program that consolidates my departments everyday work duties. I work for a duplication company that burns digital media for libraries. Right now the program I made is "hard coded" to display 2 specific folders in a tree-view. However the company has been changing around the network drives and the folder paths keep changing. This results in me having to open the project, change the paths, re-publish the project, and then re-install it on all the machines (12).

    I have made a new form in the project called "settings" and would like the user to be able to open up the settings form to search for a folder path and "Save" it. I assume I would save the path as a label.text and then in the tree-view code set the path to "Folder A" = lable.text and "Folder B" = lable2.text.

    But I am stumped as to how to setup the navigation to a folder and saving the path as a label. I am new to programming but have been trying to learn as much as possible. Once I figure this out I think I can figure out how to save user settings so they wont erase when the program closes.

    So far I tried OpenFileDialog but I think that is just for files. Thanks for you help in advance everyone.
    This forum has been mroe than helpful.

  2. #2
    Frenzied Member IanRyder's Avatar
    Join Date
    Jan 2013
    Location
    Healing, UK
    Posts
    1,232

    Re: Search for a folder path and save it as a variable.

    Hi,

    You need to use a FolderBrowserDialog control to do what you are looking for. You can then setup a Variable in the Settings of your Project as type System.Collections.Specialized.StringCollection, saving your folder paths as you need. Then each time you load your projects you can Read your setting and populate your TreeView as necessary. i.e-

    To save your folders:-
    Code:
    If FolderBrowserDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
      If IsNothing(My.Settings.tvFolders) Then
        My.Settings.tvFolders = New System.Collections.Specialized.StringCollection
      End If
      My.Settings.tvFolders.Add(FolderBrowserDialog1.SelectedPath)
    End If
    To read your folders:-
    Code:
    If Not IsNothing(My.Settings.tvFolders) Then
      For Each strFolder In My.Settings.tvFolders
        'Add folders to the TreeView
        MsgBox(strFolder)
      Next
    End If
    Hope that helps.

    Cheers,

    Ian

  3. #3

    Thread Starter
    Member
    Join Date
    Apr 2013
    Posts
    42

    Re: Search for a folder path and save it as a variable.

    Ian this is exactly what I was looking for. Sorry if I'm asking rudimentary questions.

    You have delivered yet again. Thank you so much.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width