Click here to Skip to main content
13,556,387 members
Rate this:
Please Sign up or sign in to vote.
See more:
No idea why this isnt working its just a couple of .txt files and no expection is being outputted.

What I have tried:

          string[] array2 = Directory.GetFiles(@"C:\Users\Public\LSH\SearchingDB\", "*.txt");
          if (array2.Length == 0)
              Console.WriteLine("No files found.");
          foreach (string name in array2)
              if (name.Contains(TextBox1.Text))
      catch (Exception excpt)
Posted 19-May-17 13:13pm
Updated 19-May-17 14:04pm
NotPolitcallyCorrect 19-May-17 19:40pm
So debug your code. We can't do it for you. GetFiles most certainly does work so you are not doing something right.
geswan 20-May-17 2:44am
Check that TextBox1.Text does not contain control characters such as 'return' or 'newline'
aishwaryashivapareek 20-May-17 11:29am
What is the output? Is it blank or what? Is it displaying "No files found"?

If you don't know how to debug in VS then give me a free call here:I will help you.
NotPolitcallyCorrect 20-May-17 13:21pm
You can stop spamming the forum now, thanks.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Ummm...You never said what "isn't working". That's not a proper problem description.

GetFiles works just fine. The first thing I'd check is the path you gave it. Either the path doesn't exist, or you don't have permissions to it, or there are no files with the extension of "txt" in that folder.

Next, run this in the debugger, set breakpoints, step through the code and inspect the contents of variables to see what in them. Right now, you're just guessing at what you're code is doing.

Something else goofy is that there is no Console in a Windows Forms app. Any output from the Console methods get output to the Output window in Visual Studio. This should really be replaced by Debug.WriteLine instead.

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 |
Web04-2016 | 2.8.180515.1 | Last Updated 19 May 2017
Copyright © CodeProject, 1999-2018
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