Skip to content

Get directory in C#

Freddy Abreu

Freddy Abreu

Asked Jul 26, 2013, 6:57 AM EDTSolved
Share
LinkedInX
Hi everyone

Is my first time trying to get the specific path of a directory please, Why  I can not get the path of this program into my listview?

       
        void MainFormLoad(object sender, EventArgs e)
        {
                listView1.View = View.Details;
                listView1.GridLines = true;
                listView1.FullRowSelect = true;
                listView1.Columns.Add("Directory list:");
                
                
        }
        
        void Button1Click(object sender, EventArgs e)
        {
            
                string[] Path = Directory.GetFiles(@"C:\Windows\Microsoft.NET\",".dll",SearchOption.AllDirectories);
                
                
                foreach (var list in Path){
                var items = listView1.Items;
                items.Add(list);
                
                
               
                
                
            }
                
                            
            
        }
    }
}

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • ✓ Accepted answer0
    Hi,
    Your search query is wrong. 
    string[] Path = Directory.GetFiles(@"C:\Windows\Microsoft.NET\","*.dll",SearchOption.AllDirectories);

    When you want to filter all the dlls then you need to use *.dll. In your code, you used as ".dll" which will not return anything..


    Hope this helps you. !
    0
  • Freddy Abreu
    0
    Note: Every steps any of you going to make, please explain me as a two years old kid.
    0
  • 1 short reply
    • Freddy Abreu
      0
      Exactly, thanks, It worked!
      0