I need you to clear my point. I can use the application in SaveFileDialog stupid here but I'm a bit stuck. Basically, I have a OpenFileDialog to search .xml file and displays it in a datagridview. Then I will wish to export the contents of the datagridview to CSV files. And that is where it stops .... My SaveFileDialog is said but I know I have a writing worries but the beginning I did not understand why and how ...
I am entitled to this: 'Stream' does not contain a definition for 'WriteLine' and no extension method 'WriteLine' accepting a first argument of type 'Stream' was found (a using directive or reference to 'assembly-it is missing?)
When I put my comments in two lines myStream.writeline bah it tells me it is exported but empty CSV (normal what)
Can you help me please ?
private void SaveBtn_Click(object sender, EventArgs e)
{
Stream myStream;
SaveFileDialog enregistrercsv = new SaveFileDialog();
enregistrercsv.Filter = "Fichier CSV (*.csv)|*.csv|All files (*.*)|*.*";
if (enregistrercsv.ShowDialog() == DialogResult.OK)
{
if ((myStream = enregistrercsv.OpenFile()) != null)
{
string strHeader = "";
for (int i = 0; i < dataGridView1.Columns.Count; i++)
{
strHeader += dataGridView1.Columns[i].HeaderText + ",";
}
myStream.WriteLine(strHeader);
for (int m = 0; m < dataGridView1.Rows.Count; m++)
{
string strRowValue = "";
for (int n = 0; n < dataGridView1.Columns.Count; n++)
{
strRowValue += dataGridView1.Rows[m].Cells[n].Value + ",";
}
myStream.WriteLine(strRowValue);
}
}
myStream.Close();
MessageBox.Show("Fichier CSV créé avec succès FUCK YEAH");
}
}
Thank you guys