Dahico
Dahico

Reputation: 66

FileSystemWatcher on folder on desktop (or C drive)

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.

  1. I gave EVERYONE full privilige on that folder
  2. I tried publishing it with click once for full trust application. But it failed also with published edition
  3. Tried to run exe file and visual studio as administrator. Nothing changed
  4. Tried absolute path and Extra filters.

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
        }

Upvotes: 0

Views: 722

Answers (1)

Dahico
Dahico

Reputation: 66

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

Upvotes: 1

Related Questions