Hii every one ....

I want to list out directories or folders or files which are in perticular folder or directory ...
there is a control in VB 6.0 dirlistbox.
Is there any control like that in C#.

or

open my computer and any drive of my computer..
now see all the files and folder in details view ...

is there any control in C# to obtain that same view on my C# form??
if not?/
than in wht direction i should procedd to obtain such view ...
thnks ...

Recommended Answers

All 9 Replies

Hi,

Use namespace System.IO which contains the DriveInfo, DirectoryInfo, FileInfo classes. From these classes, we can get the files and folders (corresponding methods are available). To get the drives, use System.Environment.GetLogicalDrives method.

With these combination, we can create a form like windows explorer view.

Good luck.

You could use the FolderBrowserDialog.
More info about this class can be found here

thnks for your reply ...
i know this things ..
but in windows explorer they display icon related to that files or folder ...
how can i do that??
can i obtain that icon path throgh the name of that file??

and there is no control like vb 6.0 in C#.net ...

thnks ddanbe ...
but i dont want that tree view structure ..
i want structure like details view in my computer or in any drive ...

from view we setting like details view,tiles etc... view ...
i want look n feel like details view ...

any control for this ???

or how can i get icon of file through that files name ..
thkns

Use the listview. Notice how in windows explorer you can use icons, details view, column view, etc. You can do the same thing with a listview.

Someone on code project has authored an icon extracter class:
http://www.codeproject.com/KB/cs/IconExtractor.aspx

Give that a shot.

have you tried the openFileDialog? It has the same view as the explorer window, with a dropdown to select views such as details/large icons etc.

As pointed out, I believe you are looking for the OpenFileDialog given the VB name you specified. Here is the basic setup and call for dialog:

string fileName;

            using (OpenFileDialog ofd = new OpenFileDialog())
            {
                ofd.Title = "Select File";
                ofd.InitialDirectory = "c:";
                ofd.FileName = "";
                ofd.Filter = "All Files (*.*)|*.*";
                ofd.Multiselect = false;

                if (ofd.ShowDialog() == DialogResult.OK)
                    fileName = ofd.FileName;
            }

You may wish to refer to documentation for further options and details.

Cheers!

Hey ...
thnks a lot all of you ...
finally i have done it with Grid view ...
thnks a lot ...

Here is some code that I wrote a while back, it populates a TreeView with the directories and files from the path in the textbox. You will need to add a TreeView control to your form, a button, and a textbox for the path.

private void button1_Click(object sender, EventArgs e)
        {
            string path = txtFolderView.Text;
            TreeNode node = default(TreeNode);

               
                 TreeView1.Nodes.Clear();

                 if (System.IO.Directory.Exists(path) || System.IO.File.Exists(path))
                 {
                     try
                     {

                         node = TreeView1.Nodes.Add(path);


                         node.Tag = path;


                         ListFiles(path, node);
                     }
                     catch (Exception)
                     {
                         //error handling
                     }
                 }
                 else
                 {
                     //error handling
                 }
   
         }
        

    private void ListFiles(string path, TreeNode node)
    {

        try
        {

        string[] folders = System.IO.Directory.GetDirectories(path);
        string[] files = null;
       
        TreeNode newnode = default(TreeNode);
      
        node.Nodes.Clear();
      
       foreach (string folder in folders)
      {
          
          newnode = node.Nodes.Add(System.IO.Path.GetFileName(folder));
          
             
          newnode.Tag = folder;
      }
      
      
           files = System.IO.Directory.GetFiles(path);
          
           foreach (string file in files)
           {
               newnode = node.Nodes.Add(System.IO.Path.GetFileName(file));
               newnode.Tag = file;
           }
      }
       catch (Exception msg)
      {
          MessageBox.Show(msg.ToString());
          
          
      }
   }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.