App.config vs <<AppName>>.exe.config handling

R

Ranjith Venkatesh

I read and write to a config file which is the data store for this Windows
Application written in C# using VS.NET 2003 in Windows XP.

Now I want to trigger the program to read the config whenever I change it.

I use a FileSystemWatcher with the path set to
System.IO.Directory.GetCurrentDirectory(); and Filter set as

<<AppName>>.exe.config

Now even when

<<AppName>>.exe.config is changed the FileSystemWatcher does not seem to
catch the event.

What I am doing incorrectly here?
 
G

Guest

Could you post the code you are using for the FSW. Given the situation you
defined it would be hard to identify the problem. However a few things you
can check for are:

1) System.IO.Directory.GetCurrentDirectory() is not the correct way to
locate the config file since the working directory of an application can be
changed at will. Use
AppDomain.CurrentDomain.SetupInformation.ConfigurationFile instead.
2) Did you remember to hook up events to FSW in addition to setting the
NotifyFilter property? I have found that some programs will actually delete
a file and recreate it when saving so simply watching for modification is not
always enough.
3) Did you set the EnableRaisingEvents to true? This is what really starts
the watcher.

Posting the code will permit any potential coding errors to stand out.

Thanks,
Michael Taylor - 6/17/05
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top