To select a CSV file in C#, we can use OpenFileDialog class from WinForms namespace. Here is how we can use OpenFileDialog to select a CSV file:
main.cs364 chars15 lines
As we have got the file path, now we can add a new Yes/No column to the CSV and move the file to the destination. Here is the code to add a new column and move the CSV file to a destination folder:
main.cs583 chars19 lines
Here, targetFolderPath
is the path of the destination folder where we want to move the updated CSV file.
This code reads all the lines from selected CSV file and adds a new Yes column to each line. After that, it saves the updated lines to a new CSV file named "_updated.csv"
. Finally, it moves the original CSV file to the destination folder and renames it with the original filename.
gistlibby LogSnag