I am creating a winforms project which checks files in folder. It only works when new file put in the folder. I am using FileSystemWatcher. It works fine on D drive but fails on C drive.
It does not raise any errors. Simply does nothing.
Non Working Code
string desktop = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
teklifwatcher.Path = desktop+"\\XMLTeklif";
teklifwatcher.NotifyFilter = NotifyFilters.LastWrite;
teklifwatcher.Filter = "*.xml";
teklifwatcher.Changed += new FileSystemEventHandler(TeklifXML);
teklifwatcher.EnableRaisingEvents = true;
private void TeklifXML(object sender, FileSystemEventArgs e)
{
//dostuff
}
I solved this problem on my own. I assume filesystemwatcher can't watch c: drive files directly. Because of the security reasons. But we can use Program Files (X86) folders just like any other application.
Anyone who have similar problems just use filesystemwatcher on a folder at program filex(x86). And give permissions to that folder. Voila! It works