kevin bredahl

kevin bredahl

  • NA
  • 18
  • 6.8k

search files = problems

May 18 2014 12:10 PM
hi
i try to list all file of certain type from my c drive. but i run into the same problem every time

(Access to the path 'C:\$Recycle.Bin\S-1-5-18' is denied.)

how can i work around this problem.
my code is the following:

private void button1_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
var files = Directory.EnumerateFiles(@"C:\", "*" + comboBox1.SelectedItem.ToString(), SearchOption.AllDirectories);

foreach (string file in files)
{
string filename = Path.GetFileNameWithoutExtension(file);
ListViewItem item = new ListViewItem(filename);
item.Tag = file;
listView1.Items.Add(item);
}

}

Answers (8)