Home All Groups Group Topic Archive Search About

system.configiration .net 2.0 - save

Author
4 Nov 2005 12:48 PM
Andrzej Kaczmarczyk
Hello,

I am having troubles saving configuration file.

I did the folloing: inherited from ConfigurationSection,
ConfigurationCollection, ConfigurationElement to define my own element in
config file.

If I do the following:

using System.Configuration;

System.Configuration.Configuration configFile;
this.configFile =
ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
DatabaseConnectionSection dcs;
dcs = new DatabaseConnectionSection();
DatabaseConnectionSettings cn = new DatabaseConnectionSettings();
cn.Name = "connectionName";
dcs.Connections.Add(cn);
this.configFile.Sections.Add(DatabaseConnectionSection.Name, dcs);
this.configFile.Save(ConfigurationSaveMode.Full);

everything works fine, I can save and load the settings on the next run.

Hoever I'd like to store the section in separate file.
So after dcs instantiation I did:
dcs.SectionInformation.ConfigSource = "DatabaseConnections.config";

on execution of the last line in above I get an exception "Object reference
not set to an instance of an object."
the config file has this file added:
  <DatabaseConnections configSource="DatabaseConnections.config" />

But the file itself isn't created and the application can't start on the
next run because of this.

I think, the problem is in the filePath or there is something else I need to
set in SectionInformation, but the docs aren't clear about that

CUIN Kaczy

AddThis Social Bookmark Button