Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#4.0
hi

how to find a specific file in a Folder.
 
in WinForm Application
Posted 4-Jul-13 3:22am
rahuls11.1K
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Use the static methods in the type System.IO.Directory.
The method's name is GetFiles(...) and comes with three different signatures:
 
Excerpt from MSDN:
String[] GetFiles(String)                        //Returns the names of files (including their paths) in the specified directory.
String[] GetFiles(String, String)                //Returns the names of files (including their paths) that match the specified search pattern in the specified directory.
String[] GetFiles(String, String, SearchOption)  //Returns the names of files (including their paths) that match the specified
                                                   search pattern in the specified directory, using a value to determine whether to search subdirectories.
 
Regards,
 
— Manfred
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Using this C# code, a window application can access/find all or a specific file (if mentioned) in a Folder.on load
use
 
<pre lang="cs">private void Form1_Load(object sender, EventArgs e) {
            string[] array1 = Directory.GetFiles(@"C:\MyTemplates", "*.docx");
            foreach (string name in array1) {
                comboBox1.Text = name;
                comboBox1.Items.Add(Path.GetFileName(name));
            }
        }&lt;/pre&gt;</pre>
  Permalink  
Comments
Mulla Rameez at 4-Jul-13 8:56am
   
Use System.IO.Directory.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 95
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 4 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100