none
How to list files and folders inside a Directory or a folder

    Question

  • Hello,

    I have a application where I need the folder names and files inside the directory and I want to put the folder names and filenames to a Tree control or to a ComboBox or to a ListBox. 

    For example I have to list all the .mp3 songs in "D:/Music" and I want to put all the filenames and folder names in TreeView.
    Help me out to do this.

    Thanks
    Wednesday, January 06, 2010 6:50 AM

Answers

  • Use Directory.GetFiles to enumerate the files in a directory. If you wish to put this data inside a treeview control you can do so.
    Controls for WPF, Windows Forms and Silverlight at http://www.divelements.co.uk
    • Marked as answer by Vyasa Wednesday, January 06, 2010 11:14 AM
    Wednesday, January 06, 2010 10:40 AM

All replies

  • Hi,
    If it is a folder browser dialog you are looking for you can use the one provided in windows forms.
    Check this link for more details.

    Or if you are trying to create a custom one for yourself
    See this link

    Hope it helps
    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
    Wednesday, January 06, 2010 7:09 AM
  • Hi Rahul,

    As I'm new to this Platform I'm not able to do it by seeing your link.. I'm trying to understand it but I need more help ..
    Can you help me for doing my application..?

    Thanks
    Wednesday, January 06, 2010 8:08 AM
  • Hi,
    Kindly tell what is the problem that you are facing.

    Thank You
    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
    Wednesday, January 06, 2010 8:31 AM
  •  Hi Rahul,

    The sample code which you posted is in VB. I am aware of VC++ syntax but in WPF we need C# . So can you  translate your sample code to WPF..?

    Thanks
    Wednesday, January 06, 2010 8:40 AM
  • Hi,
    Vb.net is also supported in WPF if you are unaware of it.
    Check this link for how to create a project .
    To convert between c# and vb you can use this .

    Hope it helps.
    Feel free to ask if you need any further help
    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
    Wednesday, January 06, 2010 10:21 AM
  • Use Directory.GetFiles to enumerate the files in a directory. If you wish to put this data inside a treeview control you can do so.
    Controls for WPF, Windows Forms and Silverlight at http://www.divelements.co.uk
    • Marked as answer by Vyasa Wednesday, January 06, 2010 11:14 AM
    Wednesday, January 06, 2010 10:40 AM
  • Thanks Tim and Rahul,

    Here is what I have done to list the files in the listbox .

       string[] filenames = Directory.GetFiles("E:\\", "*.mp3"); 
                foreach(string filename1 in filenames)
                listview.Items.Add(filename1);



    above link helped me a lot.

    Wednesday, January 06, 2010 11:21 AM