Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:15:26+00:00 2026-06-12T10:15:26+00:00

I have a Folder which has multiple sub folders. Each sub folder has many

  • 0

I have a Folder which has multiple sub folders. Each sub folder has many .dot and .txt files in them.

Is there a simple solution in C# .NET that will iterate through each file and check the contents of that file for a key phrase or keyword?

Document Name        Keyword1         Keyword2         Keyword3        ...
  test.dot              Y               N                Y

To summarise:

  1. Select a folder
  2. Enter a list of keywords to search for
  3. The program will then search through each file and at the end output something like above, I am not to worried about creating the datatable to show the datagrid as I can do this. I just need to perform the find in files function similar to Notepad++’s find in files option

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:15:28+00:00Added an answer on June 12, 2026 at 10:15 am

    What you want is recursively iterate files in a directory (and maybe it’s subdirectories).

    So your steps would be to loop eeach file in the specified directory with Getfiles() from .NET. then if you encounter a directory loop it again.

    This can be easily done with this code sample:

      public static IEnumerable<string>  GetFiles(string path)
      {
            foreach (string s in Directory.GetFiles(path, "*.extension_here"))
            {
                  yield return s;
            }
    
    
            foreach (string s in Directory.GetDirectories(path))
            {
                  foreach (string s1 in GetFiles(s))
                  {
                        yield return s1;
                  }
            }
      }
    

    A more indepth look on iterating throug files in directories in .NET is located here:

    http://blogs.msdn.com/b/brada/archive/2004/03/04/84069.aspx

    Then you use the IndexOf method from String to check if your keywords are in the file (I discourage the use of ReadAllText, if your file is 5 MB big, your string will be too. Line-by-line will be less memory-hungry)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website which has so many sub folders in it. I have
I have a document library in MOSS 2007 which has folders and files. Document
I have a folder which contains doc, docx, xlsx, pdf and txt files. I
I have a folder structure that contains multiple javascript files, each of these files
I have a folder called Etc which has an image I want to use
I have a folder C:\Images which has a some images. This folder is not
I have a Visual Studio Setup project which has a Application Folder DefaultLocation set
I have a folder which contains few files and some directories which I need
I have a content folder which is full of other sub-directories named in the
I have cloned a git repo which has my emacs config files in. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.