Rano AH

Rano AH

  • NA
  • 176
  • 111.9k

List all the files inside a speciifc directory / folder

Apr 13 2014 9:26 AM

Hi,

I created two forms, first one contains a command button that open another form to list all the files inside a specific directory/folder


private void showItemsInTheDirectory()
        {
            DirectoryInfo currentDirectory = new DirectoryInfo(@"C:\Users\UserName\MyDocuments");
            FileInfo[] files = currentDirectory.GetFiles();

            foreach (FileInfo file in files)
            {
                ListView listView1 = new ListView();
                ListViewItem item = new ListViewItem();
                item.Text = file.Name;
                listView1.Items.Add(item);
            }

            Form1 form1 = new Form1();
            form1.Show();
 }

This reads all the files inside the directory and open a another form but It doesn't list all the file names. What should I add?


Answers (9)