private void button1_Click(object sender, EventArgs e) { string strValue = string.Empty; for (int i = 0; i < dataGridView1.Rows.Count - 1; i++) { for (int j = 0; j < dataGridView1.Rows[i].Cells.Count; j++) { if (!string.IsNullOrEmpty(dataGridView1[j, i].Value.ToString())) { if (j > 0) strValue = strValue + "," + dataGridView1[j, i].Value.ToString(); else { if (string.IsNullOrEmpty(strValue)) strValue = dataGridView1[j, i].Value.ToString(); else strValue = strValue + Environment.NewLine + dataGridView1[j, i].Value.ToString(); } } } } string strFile = "c:\\Active Dir File.csv"; File.WriteAllText(strFile, strValue); MessageBox.Show("File Saved in C:"); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)