app.config modification issue in Windows 7

February 28, 2010 by: Sanket

File modification issue in Windows 7 for program files content

We have developed many windows application using C# or VB.NET.

In that we stored connection string and other required data in ‘app.config’ file, and we modify that file using our application to store latest connection or other information.

This is standard practice and works as well.

But in ‘Windows 7’ OS architecture is changed in teams of security and other features.

So we can’t modify files which are in % program file % application directory %.

There are there options, run application as administrator. We can run it as admin, but we can’t guarantee that all of our customer will !!!

Other option is keep it same, means write in app.config which will be there in program files.

It will work as desired but ‘content will not be modified in config file from program files’, this is due to one feature of windows 7 called as ‘Common file and registry virtualization

Whatever you modify in app.config or program files, it will be get modified in virtual file which stored in ‘%userprofile%\AppData\Local\VirtualStore’. And when you try read app.config, it will be read from virtual space rather from program files.

There is no harm with this approach, but you will have to delete the virtual file when you uninstall the application.

The other and safe way for this issue is to use ‘application data’ space of windows OS. All the major applications including word, outlook stores there data in app data.

So it is good habit to store your data there.

  • Share/Bookmark

Comments

One Response to “app.config modification issue in Windows 7”

Leave a Reply