file change event
How do I get my program to run a function when a specific file has changed?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Kirtan PatelPosted Oct 16, 2009, 3:47 PM
using System.IO;
private void Form1_Load(object sender, EventArgs e)
{
FileSystemWatcher fsw = new FileSystemWatcher(@"E:\", "*.txt");
fsw.EnableRaisingEvents = true;
fsw.NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Attributes;
fsw.Changed += new FileSystemEventHandler(fsw_Changed);
}
public void fsw_Changed(Object Sender, FileSystemEventArgs e)
{
if (e.Name == "Test.txt")
{
MessageBox.Show("File Changed !!");
}
}Roei BarPosted Oct 16, 2009, 3:37 PM
either via a control called FileSystemWatcher
like this
http://www.codeproject.com/KB/vb/AdvancedFileSystemWatcher.aspx
or via a timer that will check on the file on every period of time and update the application on that.