Using Win Explorer to choose a path
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Using Win Explorer to choose a path

  1. #1
    Join Date
    Oct 2009
    Posts
    3

    Arrow Using Win Explorer to choose a path

    I want the user of my window's forms app to be able to set a path, i.e. "c:\users\eli\desktop\example.txt", by have them click a button that opens windows explorer to a specified folder, wherein the user can double click one of the items in the folder to choose it (at which point the path to the chosen file would be stored into a string for later use). Really it would be just like WinRar or any of the many many other apps that let you 'explore' to find a file.

  2. #2
    Join Date
    Oct 2009
    Posts
    3

    Re: Using Win Explorer to choose a path

    in case that was unclear, my question is "how can i do that?"

  3. #3
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: Using Win Explorer to choose a path

    Code:
     private StringBuilder GetSelectedFolderPath()
            {
                StringBuilder selectedFolderPath = new StringBuilder("C:\'Temp");
                //Assign some  default path
    
                using (FolderBrowserDialog fbd = new FolderBrowserDialog())
                {
                    fbd.SelectedPath = "C:\'Temp";
                    if (fbd.ShowDialog() == DialogResult.OK)
                    {
                        selectedFolderPath = new StringBuilder(fbd.SelectedPath);
                    }
                }
    
                return selectedFolderPath;
            }

  4. #4
    Join Date
    Jun 2008
    Posts
    2,477

    Re: Using Win Explorer to choose a path

    Not sure why you would use a StringBuilder in that example. Also, you assign selectedFolderPath a value and never use it (it is wiped out by the assignment in the if statement).

  5. #5
    Join Date
    Oct 2009
    Posts
    3

    Re: Using Win Explorer to choose a path

    Thanks a lot vcdebugger! It's much appreciated

  6. #6
    Join Date
    May 2009
    Location
    Bengaluru, India
    Posts
    422

    Re: Using Win Explorer to choose a path

    BigEd781

    I have used StringBuilder to store the selcted path - but in this case I have hardcoded 'C:/Temp" as the path or else "fbd.SelectedPath" might have the actual path selected by the user in the BrowserDialog.

Tags for this Thread

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center