I am working on a Program which allows to open and save data from/to a file and does the same with a database if you wish. So far I only have some Text columns, saving those was no big deal, now my teacher asked me to add a picture column, which also worked. But as my datagridwiev was only text when I created it, I could easily save it in a text file... with a picture this would no longer work. Using my old code:
The txt file displays something like
--> col1 | col2 | col3 | System.Drawing.Bitmap
any Ideas how I can change my saveFileDialog so it would work with both text and an image?
what I have so far:
private void button1_Click_1(object sender, EventArgs e) //Save to File Button
{
SaveFileDialog SaveDialog = new SaveFileDialog();
SaveDialog.InitialDirectory = @"C:\";
SaveDialog.Title = "Save text Files";
SaveDialog.CheckFileExists = false;
SaveDialog.CheckPathExists = false;
SaveDialog.DefaultExt = "txt";
SaveDialog.Filter = "txt files (*.txt)|*txt";
if (SaveDialog.ShowDialog() == DialogResult.OK)
{
var csv = new StringBuilder();
for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
{
var NameCell = dataGridView1.Rows[i].Cells["ColName"].Value;
var AdrCell = dataGridView1.Rows[i].Cells["Adresse"].Value;
var TelCell = dataGridView1.Rows[i].Cells["Telefon"].Value;
var PicCell = dataGridView1.Rows[i].Cells["Bild"].Value;
var newLine = string.Format("{0}|{1}|{2}|{3}", NameCell, AdrCell, TelCell);
csv.AppendLine(newLine);
}
File.WriteAllText(SaveDialog.FileName, csv.ToString());
MessageBox.Show("Saved!");
}
}