select csv file and for each line add a new column called situation with any thig and move the new csv to destination in csharp
main.cs
using System;
using System.IO;
using System.Linq;
namespaceCsvManipulation{
classProgram {
staticvoidMain(string[] args) {
// csv file pathstring filePath = @"C:\example\input.csv";
// read all lines from csvstring[] csvLines = File.ReadAllLines(filePath);
// header of new columnstring newColumnHeader = "Situation";
// adding new column header to existing header rowstring[] headers = csvLines.First().Split(',');
string[] newHeaders = headers.Append(newColumnHeader).ToArray();
// adding data to new column for each rowstring[] newData = csvLines.Skip(1)
.Select(line =>
{
string[] cols = line.Split(',');
string situationData = "Something"; // setting value for new columnstring[] newCols = cols.Append(situationData).ToArray();
returnstring.Join(',', newCols);
})
.ToArray();
// combining new headers and data to form a new csvstring newCsv = string.Join(Environment.NewLine, newHeaders.Concat(newData));
// writing new csv to destination pathstring destinationPath = @"C:\example\output.csv";
File.WriteAllText(destinationPath, newCsv);
}
}
}