Click here to Skip to main content
12,401,628 members (32,702 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# C#4.0
hi

how to find a specific file in a Folder.

in WinForm Application
Posted 4-Jul-13 2: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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.160721.1 | Last Updated 4 Jul 2013
Copyright © CodeProject, 1999-2016
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