title: C# Importing csv files in datagridview
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/1375410/very-simple-c-sharp-csv-reader">Very simple C# CSV reader</a>  </p>
  </blockquote>
  
  
  
  <p>In my application the user can export and csv files from and to a datagridview, this works okay but there is some minor problem.</p>
  
  <p>As you know csv files use the comma sign to sepperate items.</p>
  
  <p>Sometimes one of the cells has a comma sign for example (2,5 hours).</p>
  
  <p>When importing the csv it thinks that the comma sign between 2,5 is a seperator, because of this it will put 2 in a cell and 5 in the next one.</p>
  
  <p>How can i fix this problem.</p>
  
  <p>This is my csv for importing csv's </p>
  
  <pre><code>dataGridView1.Rows.Clear();
          try
              {
                  if (openFileCsv.ShowDialog() == DialogResult.OK)
                  {
                      string csvPath = openFileCsv.FileName;
  
                      if (System.IO.File.Exists(csvPath))
                      {
                          System.IO.StreamReader fileReader = new System.IO.StreamReader(csvPath, false);
  
  
                          //Reading Data
                          while (fileReader.Peek() != -1)
                          {
                              fileRow = fileReader.ReadLine();
                              fileDataField = fileRow.Split(',');
                              dataGridView1.Rows.Add(fileDataField);
                          }
                          fileReader.Dispose();
                          fileReader.Close();
                      }
                      else
                      {
                          MessageBox.Show("CSV Bestand niet gevonden.");
                      }
                  }
  
                  DataLoaded = true;
  
              }
  </code></pre>
  
  <p>This is my code for exporting the csv.</p>
  
  <pre><code>if (saveFileCsv.ShowDialog() == DialogResult.OK)
              {
                  string CsvFpath = saveFileCsv.FileName;
  
                  try
                  {
                  System.IO.StreamWriter csvFileWriter = new System.IO.StreamWriter(CsvFpath, false);
  
              int countColumn = dataGridView1.ColumnCount - 1;
  
              int iColCount = dataGridView1.Columns.Count;
  
              foreach (DataGridViewRow dataRowObject in dataGridView1.Rows)
              {
                  //Checking for New Row in DataGridView
                  if (!dataRowObject.IsNewRow)
                  {
                      string dataFromGrid = "";
  
                      dataFromGrid = dataRowObject.Cells[0].Value.ToString();
  
                      for (int i = 1; i &lt;= countColumn; i++)
                      {
                          dataFromGrid = dataFromGrid + ',' + dataRowObject.Cells[i].Value.ToString();
                      }
  
                      //Writing Data Rows in File
                      csvFileWriter.WriteLine(dataFromGrid);
                  }
              }
  
  
              csvFileWriter.Flush();
              csvFileWriter.Close();
          }
          catch (Exception exceptionObject)
          {
              MessageBox.Show(exceptionObject.ToString());
          }
  </code></pre>