0

I have a csv file and I would like to make some actions whenever a new row is inserted to this csv file.

is there such a listener in c#?

Thanks a lot

Marco Dinatsoli
  • 10,322
  • 37
  • 139
  • 253
  • possible duplicate of [c# continuously read file](http://stackoverflow.com/questions/3791103/c-sharp-continuously-read-file) – xmojmr Jan 25 '15 at 11:02

3 Answers3

0

There is a class FileSystemWatcher to inspect the file changes. FileSystemWatcher MSDN. in your case, you just need to filter with "*.csv".

Rohit Prakash
  • 1,975
  • 1
  • 14
  • 24
0

No, there is not specifically a listener for a row being added, but there is such a thing, in .Net, as a FileSystemWatcher, which is a class that can monitor a file for changes. With it, you can react to a specific set of changes to the file that you choose, but what happens is completely up to you.

dodexahedron
  • 4,584
  • 1
  • 25
  • 37
0

You can use the FileSystemWatcher to watch an arbitrary file for change events:

public MainWindow()
{
    InitializeComponent();

    FileSystemWatcher fsw = new FileSystemWatcher();
    fsw.Filter = "test1.csv";
    fsw.NotifyFilter = NotifyFilters.LastWrite;
    fsw.Path = "z:\\temp\\";
    fsw.Changed += Fsw_Changed;
    fsw.EnableRaisingEvents = true;    
}

private void Fsw_Changed(object sender, FileSystemEventArgs e)
{
    MessageBox.Show(e.FullPath);
}
John Koerner
  • 37,428
  • 8
  • 84
  • 134
  • In this approach, i would be notified for updates on the file, but I would need to parse the whole file to find the last row, which is the new inserted row in the csv, am i right please? – Marco Dinatsoli Jan 24 '15 at 12:44