title: export large datatable data to .csv file in c# windows applications
body: <p>I need to export large <code>DataTable</code>(> 50 lacs( 5M ) DataRows ) to a <code>.csv</code> file </p>
  
  <p>I am using the below code, but its taking long time.</p>
  
  <pre><code>public void CreateCSVFile(DataTable dtDataTablesList, string strFilePath)
  {
      // Create the CSV file to which grid data will be exported.
      StreamWriter sw = new StreamWriter(strFilePath, false);
      //First we will write the headers.
      int iColCount = dtDataTablesList.Columns.Count;
      for (int i = 0; i &lt; iColCount; i++)
      {
          sw.Write(dtDataTablesList.Columns[i]);
          if (i &lt; iColCount - 1)
          {
              sw.Write("", "");
          }
      }
      sw.Write(sw.NewLine);
  
      // Now write all the rows.
      foreach (DataRow dr in dtDataTablesList.Rows)
      {
          for (int i = 0; i &lt; iColCount; i++)
          {
              if (!Convert.IsDBNull(dr[i]))
              {
                  sw.Write(dr[i].ToString());
              }
              if (i &lt; iColCount - 1)
              {
                  sw.Write("", "");
              }
          }
          sw.Write(sw.NewLine);
      }
      sw.Close();
  }
  </code></pre>
  
  <p>Kindly let me know any another way of doing quickly.</p>