Click here to Skip to main content
15,891,423 members
Please Sign up or sign in to vote.
1.86/5 (4 votes)
See more:

I want to write a program to find a file in c#



C#
if (File.Exists(textBox1.Text))
           {

               MessageBox.Show(textBox1.Text + "was found in your system");

           }
Posted

Not exactly sure what you are attempting to ask... However, if you want to find a file in a particular directory use this:
C#
var myFiles = Directory.GetFiles(@"c:\some\directory\");
// OR
// Find all CS files in the directory
myFiles = Directory.GetFiles(@"c:\some\directory\", "*.cs");



Reference:
http://msdn.microsoft.com/en-us/library/ms143316(v=vs.110).aspx[^]
 
Share this answer
 
Comments
goksurahsan 2-Aug-14 9:20am    
there is a file in my computer and I want to find it with c# programme. what can I do it?
Try this:

C#
var allFiles = Directory.GetFiles(path, "*.xml", SearchOption.AllDirectories);
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900