title: Speed up searching/reading from StreamReader
body: <p>I'm trying to to download a list of file names present in an FTP server and once I retrieve all names I use a StreamReader object and try to search through all file names to check the existence of a substring contained by any file present in that ftp.</p>
  
  <p>For example, if file names are like</p>
  
  <p>0000730970-0633788104-20140422073022-0633788104.PDF</p>
  
  <p>0000730970-0633789720-20140422101011-0633789720.PDF</p>
  
  <p>0000730970-0633798535-20140425075011-0633798535.PDF</p>
  
  <p>0000730970-0633798536-20140425075011-0633798536.PDF</p>
  
  <p>0000730970-0633804266-20140428124147-0633804266.PDF</p>
  
  <p>0000730970-0633805880-20140429065011-0633805880.PDF</p>
  
  <p>I'll search "0633798535" (the second or last substring separated by dash, because that's the only info I have about those files present in that ftp, do not know the full file name). Bellow code I'm using to do this</p>
  
  <pre><code>try{
  browseRequest = (FtpWebRequest)FtpWebRequest.Create(ftpAddress);
  
  browseRequest.Credentials = new NetworkCredential(username, password);
  browseRequest.UsePassive = true;
  browseRequest.UseBinary = true;
  browseRequest.KeepAlive = true;
  
  browseRequest.Method = WebRequestMethods.Ftp.ListDirectory;
  response = (FtpWebResponse)browseRequest.GetResponse();
  responseStream = response.GetResponseStream();
  
  if (responseStream != null)
  {
      using (StreamReader reader = new StreamReader(responseStream))
      {
          while (!reader.EndOfStream &amp;&amp; !isDownloaded)
          {
              string fileName = reader.ReadLine().ToString();
              if (fileName.Contains(subStringToBeFind)) //search for the first encounter
              {
                  //download the file
                  isDownloaded = true; //initially false
              }
          }
      }
  }
  }
  </code></pre>
  
  <p>Here I'm using sequential search to find the file name. But the problem is if the quantity of files is large the searching becomes slow, say for 82000 file names if I'm looking for the last file it takes like 2 minuets to search out. Because of this the application is slow. So, I need help to accelerate the searching. Is there any way to use binary search or something else to improve the searching time.</p>