User Config - Custom Location (using ApplicationSettingsBase)

A

Amitha A

I've a Windows application that has to persist user preferences into user
config file (at a pre-determined location).

I have a UserSettings class which inherits from ApplicationSettingsBase.
Here I have many properties like location,backcolor,size etc which needs to
be persisted for each windows control in my application.
I have a Get and Set method which takes the property and SettingsKey(which
is my form name) during runtime and saves the user settings using
defaultInstance.Save().
This by default is using LocalFileSettingsProvider.
The config file generated looks like
-----------------------------------------------------------------------------

<Form1>
<setting name="Name" serializeAs="String">
<value>ABC1<value>
</setting>
</Form1>

<Form2>
<setting name="Name" serializeAs="String">
<value>ABC2<value>
</setting>
</Form2>
<Form3>
<setting name="Name" serializeAs="String">
<value>ABC3<value>
</setting>
</Form3>
-----------------------------------------------------------------------------


Please observe that there are sections for each of the form.
The problem here is that the user.config is getting generated in some
default folder.
So I decided to use a CustomSettingsProvider

-----------------------------------------------------------------------------
public class CustomSettingsProvider :SettingsProvider
{
private string _configDir =
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
ConfigXmlDocument _settingsXml = null;
....
..
..
..
..
..
SetPropertyValues()
GetPropertyValues()
}
-----------------------------------------------------------------------------
Here I am able to generate the config file into predefined folder.
I see that there is no Base.SetPropertyValues and base.GetPropertyValues
exposed for these methods. I actually do not want to implement these methods
as I want the default save to happen as it happened in the previous
case(defaultInstance.Save).
Also,when I use this method,there is no provison for creating sections like
in the previous case. I have to explicitly create elements/nodes/attributes
to create the config file.It creates a simple xml file like below.It saves
only the already created properties and not the ones which were created
during runtime.Also creating sections is not possible.
I don't want to create a form1_Name,form2_Name.and so on for all the form's
names.I want to create settingskey on the fly and do a save into the config
file.Is there a way where in I can continue to use the default provider's
(i.e LocalFileSettingsProvider) save methods but still move it to some
predefined folder.
-----------------------------------------------------------------------------

<MiscSetting>
</MiscSetting>

<Password>Password@1</Password>

<IdenEntityDetails>
</IdenEntityDetails>

<ProxyServerPort>80</ProxyServerPort>

<ExportCriteriaOutputType>true</ExportCriteriaOutputType>

<UserId>[email protected] </UserId>

<ExportResultHeaderSetting>true</ExportResultHeaderSetting>

<BaseSetFormat>{1} {2} ({3})</BaseSetFormat>
-----------------------------------------------------------------------------
 

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