Question

Hi I was wondering using C# how I would view a .CSV file, add a new...

Hi I was wondering using C# how I would view a .CSV file, add a new row then save the file?

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Input csv file format

doc - Microsoft Excel Home Insert Page Layout Formulas Data Review View Team ぬCut a copy Calibri General Format Painter Merge

Output displaying the contents in the csv file

file:///c:/users/pranesh/documents/visual studio 2013/Projects/csvreaderfile/csv 4

output after adding the row in the csv file

5 4 0 1 2 2 1234

code will be

using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;

namespace csvreaderfile
{
class Program
{
static void Main(string[] args)
{
//Reading the csv file and storing it in an array
string[] arr = File.ReadAllText("..//doc.csv").Split(',');
  
for(int i=0;i<arr.Length;i++)
{
Console.WriteLine(arr[i]);
}

Console.ReadLine();
//string content to write it to the next row
string val = "7,8,9,10,11,12";

  
File.AppendAllText("..//doc.csv", val);

  
}
}
}

Please rate it, if you have any doubts please comment it.

Add a comment
Know the answer?
Add Answer to:
Hi I was wondering using C# how I would view a .CSV file, add a new...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT