i want to do accessing files and folders in listbox and when i click in any folder then thier subfolder displayed in other listbox .........

reply sooooon
.......................
magdy
.......................

So you wanna have n numbers of listboxes - depending how many subfolder you go into.
Isnt this a bit strange?
It would make sence to show on 1st listbox folders and in 2nd listBox files in this folder (if you are on root - C:, D: then show files from the root in 2nd listbox).
Wouldnt that make more sence?

I HAVE MADE THIS PROGRAM TRY THIS IT WILL SOLVE UR PROBLEM click in any folder then thier subfolder displayed in other listbox .........

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace drive_info
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DriveInfo[] alldrives = DriveInfo.GetDrives();
            listBox1.Items.Clear();
            foreach (DriveInfo d in alldrives)
            {
                listBox1.Items.Add(d.Name);
            }
       
        }

        public void getroot()
        {
            string selecteddrive = listBox1.SelectedItem.ToString();
            DriveInfo getinfo = new DriveInfo(selecteddrive);
            if (getinfo.IsReady == true)
            {
            DirectoryInfo dir = new DirectoryInfo(listBox1.SelectedItem.ToString());
            DirectoryInfo[] dirs = dir.GetDirectories("*", SearchOption.TopDirectoryOnly);
            listBox2.Items.Clear();
           
                foreach (DirectoryInfo di in dirs)
                {
                    listBox2.Items.Add(di.FullName);
                }
                return;
            }

            else
            {
                MessageBox.Show("drive not ready");
            }
        }
        public void getsub()
        {
            string selectedrive = listBox2.SelectedItem.ToString();
            DirectoryInfo dir = new DirectoryInfo(listBox2.SelectedItem.ToString());
            DirectoryInfo[] dirs = dir.GetDirectories();
            listBox3.Items.Clear();
            foreach (DirectoryInfo di in dirs)
            {
                listBox3.Items.Add(di.FullName);
            }
        }
        public void getfile()
        {
            DirectoryInfo root = new DirectoryInfo(listBox3.SelectedItem.ToString());
            FileInfo[] files = root.GetFiles();
            label8.Text = root.CreationTime.ToString();
            label9.Text = root.LastAccessTime.ToString();
            listBox4.Items.Clear();
            int filecounter = 0;
            foreach (FileInfo file in files)
            {
                listBox4.Items.Add(file.Name);
                filecounter = filecounter + 1;
            }
            label7.Text = filecounter.ToString();

        }

        

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            getroot();
        }

        private void listBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            getsub();
        }

        private void listBox3_SelectedIndexChanged(object sender, EventArgs e)
        {
            label11.Text = listBox3.SelectedItem.ToString();
            getfile();
        }

      

       
     
    }
    
}
Be a part of the DaniWeb community

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