Hi Just a question...
foreach (string file in files)
{
MessageBox.Show(String.Format("Name: {0}", file));
List<string> newColumnData = new List<string>() { file };
List<string> lines = File.ReadAllLines(file).ToList();
lines[1] += ",Name";
int index = 2;
//add new column value for each row.
lines.Skip(2).ToList().ForEach(line =>
{
//-1 for header
MessageBox.Show(index.ToString());
lines[index] += "," + newColumnData[index - 1];
index++;
});
//write the new content
File.WriteAllLines(file, lines);
}
The data looks like:(Header has 2 rows.)
7/1/2014 to 7/11/2014
Category Trans Date Post Date Merchant Name Amount
Dining Out 6/30/2014 7/1/2014 CLASSICS MARKET CAFE 8.41
Dining Out 7/1/2014 7/2/2014 CHIPOTLE 12.07
Dining Out 7/3/2014 7/6/2014 THAI CUISI 18.24
Groceries 7/2/2014 7/3/2014 FESTIVAL FOODS 12.79
I want to add a new column name example "fileName", with the value "fileName"... just for the sake of convenience.
I am receiving the same error at:
lines[index] += "," + newColumnData[index - 1];
But the value of index is never <0 when checked through debugger/MessageBox.How to add the new column in the first position instead of last column?