I have a program that goes through a CSV file and corrects some errors in the file from the export. (The original program will be fixed, this is a stopgap).
The file is imported into a datagrid, corrected and output to another datagrid for viewing/confirmation before writing the corrected file. To correct the file, it is copied to the clipboard and output using the following:
correctedFile.ClipboardCopyMode = DataGridViewClipboardCopyMode.EnableWithoutHeaderText;
// Select all the cells
correctedFile.SelectAll();
DataObject dataObject = correctedFile.GetClipboardContent();
File.WriteAllText(newFilePath + "\\" + newFileName, dataObject.GetText(TextDataFormat.CommaSeparatedValue));
However, one thing I overlooked is that the original file is a quoted CSV file. Can I easily copy the data to the clipboard with quotes? Or what is the best recourse to do this?
Edit:
"idnum","div","22071","correct","11/13/2021"
"idnum","div","22071","correct","11/13/2021"
"idnum","divXX","22071","corectXX","11/13/2021"
"idnum ","div","22071","correct","11/13/2021"
"idnum","div","22071","correctXX","11/13/2021"
That is the file as it starts. I am using winforms for the visual representation to the user. I load that into a datagridview, clone it into a second datagridview, and any "correctXX" marking that does not have a XX matching marking in the "div" field gets the XX removed. (So line 5, correctXX would be changed to correct).
Once that is done, I use the clipboard copy/write process to write it to a file. Somewhere in there I lose the quotes around each field.