I would like to make the FileSystemWatcher monitor a folder and once there is a file created inside to get the filename so after that file could be read by File.OpenRead() and a StreamReader
I have seen a lot of examples but not my case exactly:
public static void FileWatcher()
{
FileSystemWatcher watcher = new FileSystemWatcher();
watcher.Path = @"C:\Users\";
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Filter = "*.txt";
watcher.Created += new FileSystemEventHandler(OnCreated);
watcher.EnableRaisingEvents = true;
}
public static void OnCreated(object source, FileSystemEventArgs e)
{
string filename = Path.GetFileName(e.FullPath);
}
My question is how to get the filename that is going to be created in that folder and pass its path and file to since the event method is a void:
const string fileName = @"C:\Users\.txt";
using (var stream = File.OpenRead(fileName))
using (var reader = new StreamReader(stream))
Any help appreciated!
string fileName = @"C:\Users\Desktop\Project\standard.txt";