select csv file and for each line add a new column called situation and for each line fill the situation with anything and move the new csv to destination in csharp

main.cs
using System;
using System.IO;
using System.Linq;

class Program {
    static void Main(string[] args) {
        // Path to the CSV file
        string filePath = @"C:\path\to\file.csv";
        // Read all lines of the CSV file
        string[] csvLines = File.ReadAllLines(filePath);
        // Append a new column header to the first line of the CSV
        csvLines[0] += ",Situation";
        // For each line (starting from the second)
        for (int i = 1; i < csvLines.Length; i++) {
            // Append a new column value with the desired situation
            csvLines[i] += ",Anything";
        }
        // New path to the modified CSV file
        string outputPath = @"C:\path\to\new\file.csv";
        // Write all modified lines to the new CSV file
        File.WriteAllLines(outputPath, csvLines);
    }
}
827 chars
24 lines

This code reads in the CSV file at a specified file path, modifies it by adding a new column header and value to each line, and then writes the modified data to a new CSV file at a specified file path.

gistlibby LogSnag