title: Response.Write DataTable Data to Text File, ASP.net Hangs
body: <p>Very odd problem as this is working perfectly on our old Classic ASP site. We are basically querying the database and exporting around 2200 lines of text to a Text File through Response.Write to be output to a dialog box and allows the user to save the file.</p>
  
  <p>Response.Clear()
          Response.ClearContent()
          Response.ClearHeaders()</p>
  
  <pre><code>    Dim fileName As String = "TECH" &amp; test &amp; ".txt"
  
      Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", fileName))
      Response.ContentType = "text/plain"
  
      Response.Write(strHeader)
  
      Dim sw As New IO.StringWriter()
  
      Dim dtRow As DataRow
      For Each dtRow In dt3.Rows
          sw.Write(dtRow.Item("RECORD") &amp; vbCrLf)
      Next
  
      Response.Write(sw.ToString)
      Response.Write(strTrailer &amp; intRecCount)
      Response.End()
  </code></pre>
  
  <p>I can either use StringWriter or simply use Response.Write(dt.Rows(i).Item("RECORD").toString</p>
  
  <p>Either way, the Export is causing a horrendous hang on our development site. My local machine causes no hang and is almost instantaneous. The recordset isn't very large, and the lines it is writing are small. </p>
  
  <p>Anyone have any idea why this would be hanging? It does EVENTUALLY allow for a save and display the file, but it's well over 3-4 minutes.</p>