.NET 2.0 and System.Configuration.ApplicationSettingsBase

D

delfinon

Hi all,
I think that ApplicationSettingsBase class on .NET 2.0 framework is
very useful and easy to use, in order to store global and personal
paramenters for a winform application.

The only behaviour that I don't like is where it saves updated user
settings.

AFAIK it saves a file called:

<document and settings folder>\<userfolder>\Local Settings\Application
Data\<companyname>\<applicationname>_StrongName_n5qhp1elc4gnqe1a1bida0iqjryk1mun\<applicationversion>\user.config

Anyone knows hot to customize/change this default location/name?

I would like to have something without the "strong name" part, like:

<document and settings folder>\<userfolder>\Local Settings\Application
Data\<companyname>\<applicationname>\<applicationversion>\user.config

thank you in advance for your help.
N
 
S

Stoitcho Goutsev \(100\)

Hi,

In order to do that you need to implement your own SettingsProvider. By
default ApplicationSettingsBase uses LocalFileSettingsProvider.

You can start of inheriting from LocalFileSettingsProvider and overriding
SetPropertyValues method. This is the method that saves the settings. I'd
suggest to look with the Reflector in the System.Configuration.dll assembly
to see how this method is implemented. Unfortunatelly it uses internal class
of getting the folder where the user settings are stored, but you can get an
idea of how to implement this method.
 
G

Guest

Why are you thinking about doing this? You might mess up compatability with
new builds if you change this. Besides, your users shouldn't be modifying
this themselves, so does it matter how ugly the path is? Just wondering...
 
D

delfinon

The main reason is that I have also other "private" configuration files
that I want to keep in the same place/folder. Is there any way to
obtain this full path so that I can use also for my other stuff?
G


William Sullivan ha scritto:
 
G

Guest

A couple suggestions...
I believe that this config file is designed to be flexible; if you add
additional content to the config, it will not break. This is how the
Patterns and Practices group add their block configuration to an
application--they add their config sections to the program's manifest.
If you are needing to keep information in a separate location so that it can
be used across versions, I would suggest that rather than changing the
program's manifest location, create a new directory to contian your
configuration data. This should be under the user's Application Data folder
(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)).
Create a subfolder in this directory for your app data and store it. This
location will also roam with the user if the machine is on a domain.
 
D

delfinon

Thank you for your note, William. I'll add all xml serializable stuff
in the standard config file. But I have also some "binary format"
configuration file I can't put there. Agaiin is there any "supported"
way to obtain at runtime the full path/folder used by configuration
component?
N


William Sullivan ha scritto:
 

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