title: Can I get StreamReader.EndOfStream to return false after the first time I read a file?
body: <p>---short version:
  When I get to the <code>while (!checkReader.EndOfStream)</code> every time after the first, it says <code>EndOfStream = true</code>.</p>
  
  <p>---more detail:
  A user will upload a file using an Ajax AsyncFileUpload control.  I take that file, ensure it's a very specific format of csv that we use and spit it out into a GridView.  This all works great the first time through: I get the file, parse it out, and it displays great.<br>
  But, if I call this same code again anytime during the user's session the <code>StreamReader.EndOfStream = true</code>.</p>
  
  <p>For example, a user uploads a file and I spit it out into the GridView.  Oops! User realizes there are headers... I have a checkbox available with an event handler that will call the method below to re-read the original file (it's stored in a session variable). User checks the box, event fires, method gets called, but my <code>EndOfStream</code> is now true.</p>
  
  <p>I thought that <code>using ()</code> would change that flag and I have tried adding <code>checkReader.DiscardBufferedData</code> just after the while loop below, but neither of those seem to have any affect.</p>
  
  <p>What am I doing wrong?  </p>
  
  <pre><code> private void BuildDataFileGridView(bool hasHeaders)
  {   
      //read import file from the session variable
      Stream theStream = SessionImportFileUpload.PostedFile.InputStream;
      theStream.Position = 0;
  
      StringBuilder sb = new StringBuilder();
  
      using (StreamReader checkReader = new StreamReader(theStream))
      {
          while (!checkReader.EndOfStream)
          {
              string line = checkReader.ReadLine();
              while (line.EndsWith(","))
              {
                  line = line.Substring(0, line.Length - 1);
              }
              sb.AppendLine(line);
          }
      }
  
      using (TextReader reader = new StringReader(sb.ToString()))
      { 
          //read the file in and shove it out for the client
          using (CsvReader csv = new CsvReader(reader, hasHeaders, CsvReader.DefaultDelimiter))
          {
              sDataInputTable = new DataTable();
  
              try
              {
                  //Load the DataTable with csv values  
                  sDataInputTable.Load(csv);
              }
              catch
              {
                  DisplayPopupMessage("ERROR: A problem was encountered");
              }
  
              //Copy only the first 10 rows into a temp table for display.  
              DataTable displayDataTable = sDataInputTable.Rows.Cast&lt;System.Data.DataRow&gt;().Take(10).CopyToDataTable();
  
              MyDataGridView.DataSource = displayDataTable;
              MyDataGridView.DataBind();
          }
      }
  }
  </code></pre>
  
  <p>Edit: 
  SessionImportFileUpload is the actual Ajax AsyncFileUpload control being stored as a session variable (this was already the case as a previous person wrote other stuff in that uses it).  </p>