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
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
There is a class FileSystemWatcher to inspect the file changes. FileSystemWatcher MSDN. in your case, you just need to filter with "*.csv".
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.
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);
}