title: Search for a file content in c#
body: <p>Hi I'm writing a c# code where in there is a string sent as a parameter input to the method. And then the inputString has to be searched in the file and the result has to be returned. Currently I know how do I do this in the regular way(using the file IO).</p>
  
  <pre><code>[HttpPost]
          public string UsernameValidation(string username)
          {
              string text = username;
              string userExists = usernameNotAvailable;
              string line;
              System.IO.StreamReader file = new System.IO.StreamReader("~/UserData/usernameslist.txt");
  
              while ((line = file.ReadLine()) != null)
              {
                  if (line.Contains(text))
                  {
                      userExists = usernameAvailable;
                  }
  
              }
              return userExists;
          }
  </code></pre>
  
  <p>But here is the twist, my project is in MVC. I'm able to get the path of file using <code>string userDataFile = Server.MapPath("~/UserData/usernameslist.txt");</code>.</p>
  
  <p>But I'm unable to know how can I get the functionality of searching a string in a file.</p>
  
  <p>Please let me know how can I do this.</p>
  
  <p>Thanks</p>