title: File name from StreamReader C# - asp.net MVC3 to array
body: <p>my application is MVC3 C#; I am populating two dropdownlists using json using the following:</p>
  
  <pre><code>public ActionResult CheckWord(string cword)
      {
          try
          {
              List&lt;string[]&gt; arrayList = new List&lt;string[]&gt;();
              List&lt;string[]&gt; stateList = new List&lt;string[]&gt;();
              //
              List&lt;string[]&gt; fileList = new List&lt;string[]&gt;();
              //
              string[] filePaths = Directory.GetFiles(System.Web.HttpContext.Current.Server.MapPath("/Video"), "*.srt");
              string[] fnList = new string[filePaths.Length];
              for (int i = 0; i &lt; fnList.Length; ++i)
              {
                  FileInfo fi = new FileInfo(filePaths[i]);
                  fnList[i] = fi.Name.Substring(0, fi.Name.LastIndexOf(".srt"));
  
              }
              int nFiles = filePaths.Length;
              string cacheline = "";
              string line;
  
              for (int i = 0; i &lt; nFiles; ++i)
              {
                  StreamReader file = new StreamReader(System.Web.HttpContext.Current.Server.MapPath("/Video/" + fnList[i] + ".srt"));
  
                  List&lt;string&gt; lines = new List&lt;string&gt;();
                  List&lt;string&gt; statments = new List&lt;string&gt;();
                  //
                  List&lt;string&gt; fnames = new List&lt;string&gt;();
                  //
                  while ((line = file.ReadLine()) != null)
                  {
                      if (line.Contains(cword))
                      {
                          statments.Add(line);
                     //     fnames.Add(file);
                          lines.Add(cacheline);
                      }
                      cacheline = line;
                  }
                  file.Close();
                  var array = lines.ToArray();
                  arrayList.Add(array);
                  stateList.Add(statments.ToArray());
              }
  
              return Json(new { success = true, fnList = fnList, arrayList = arrayList.ToArray(), stateList = stateList.ToArray() });
          }
          catch { }
          return Json(new { success = false });
      }
  </code></pre>
  
  <p>I am checking if a word exists in a group of files; then display the names of files in one dropdownlist and the lines from each file in the other dropdownlist.  It works fine, however it gives me a list of all files becasue I am sending back fnlist.  However I am trying to display only the files that contain that word; I could not get the file name from the StreamReader and add it to an array fileList.  I would appreciate your suggestions, thanks in advance.</p>