connectseekers.com

Monday, 4 July 2016

Search File Exist or Present in Directory Windows Application Using C#.Net

7/04/2016 - By Pranav Singh 0

This article will show you how you can search a file existence it presence in a directory or folder in windows application using c#.net.


So for this article first we will create a new windows application and add some button and textbox control on form. Your form will look as shown below:

 
After this we will create click event of button and add the below code on button click event.

  private void button1_Click(object sender, EventArgs e)
        {
            string[] filePaths = Directory.GetFiles(txtDirectoryPath.Text);
            string filename = txtFileName.Text;
            foreach (string item in filePaths)
            {
                if (item.Contains(filename))
                {
                    lblmessage.Text = "File Exists";
                    break;
                }
                else
                {
                    lblmessage.Text = "File NOT Exists";
                }
            }
        }

In above code first I have fetched all the files present in the provided directory and then I have applied look to checked and every file one by one weather the file is present in the collection or not. 

If it’s found then it will show the message “File Exists” otherwise it will display “File Not Found”.
Now we have done run the application to check the output. First we will check the file directory.


 Now we will provide directory path and file name. 


 Now we will provide invalid file name.


About the Author

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Get Updates

Subscribe to our e-mail newsletter to receive updates.

Share This Post

0 comments:

Please let me know your view

Free Ebooks


About Us

We are the group of people who are expertise in different Microsoft technology like Asp.Net,MVC,C#.Net,VB.Net,Windows Application,WPF,jQuery,Javascript,HTML. This blog is designed to share the knowledge.

Contact Us

For writing article in this website please send request by your

GMAIL ID: dotnetpools@gmail.com
Email Id : contact@aspdotnet-pools.com

Bugs and Suggestions

As we all know that this website is for sharing knowledge and providing proper solution. So while reading the article is you find any bug or if you have any suggestion please mail us at contact@aspdotnet-pools.com.

Partners


Top jQuery Plugins

Global Classified : Connectseekers.com
© 2014
back to top