select csv file and for each line add a new column called situation and for each line fill the situation with yes or no and move the new csv to destination in csharp
Here is the code to read a csv file, add a new column called situation and fill it with a yes or no depending on your condition for each row, and then move the new csv file to a destination folder:
main.cs
using System;
using System.IO;
using System.Linq;
classProgram{
staticvoidMain(string[] args) {
// Get the source file path and destination folder pathstring sourceFilePath = @"C:\data\input.csv";
string destinationFolder = @"C:\data\output";
// Read the csv file into a list of string arraysvar csv = File.ReadAllLines(sourceFilePath)
.Select(line => line.Split(',').ToList())
.ToList();
// Add a new column called 'situation' and fill it with yes or no depending on your condition for each rowfor (int i = 0; i < csv.Count; i++)
{
bool condition = // your condition here csv[i].Add(condition ? "yes" : "no");
}
// Write the new csv to a temporary filestring tempFilePath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString() + ".csv");
using (var writer = new StreamWriter(tempFilePath))
{
foreach (var line in csv)
{
writer.WriteLine(string.Join(",", line));
}
}
// Move the new csv to the destination folderstring fileName = Path.GetFileName(sourceFilePath);
string destinationFilePath = Path.Combine(destinationFolder, fileName);
File.Move(tempFilePath, destinationFilePath);
}
}