The following code is used to save a CSV string, however, if I save to an existing .CSV, instead of replacing the data, it only adds the new string to the data already there. How do I remedy this? Is it something inherent to how the Stream.Write function works, or is this an idiosyncrasy of Excel and .CSV?
SaveFileDialog dialog = new SaveFileDialog();
dialog.AddExtension = true;
dialog.Filter = "CSV Files (*.csv)|*.csv|All Files (*.*)|*.*";
dialog.FilterIndex = 1;
dialog.Title = "Save As";
dialog.InitialDirectory = "C:\\";
dialog.CheckPathExists = true;
dialog.DefaultExt = ".csv";
dialog.ValidateNames = true;
if (dialog.ShowDialog() == DialogResult.OK)
{
StreamWriter myStream = new StreamWriter(dialog.FileName, true);
myStream.Write(//Function which returns a CSV-formmatted string//);
myStream.Close();
OpenFile(dialog.FileName);
}