Salut à tous,
j'ai un souci concernant les fichiers de configuration.
J'ai le fichier de config suivant:
Code :
- <configuration>
- <configSections>
- <section name="SQLSection" type="GilInterimStatsViewer.SQLSectionHandler, GilInterimStatsViewer" />
- <section name="ExportImageSection" type="GilInterimStatsViewer.ExportImageSectionHandler, GilInterimStatsViewer" />
- </configSections>
- <SQLSection type="GilInterimStatsViewer.SQLSection, GilInterimStatsViewer">
- <Server>xxx</Server>
- <DBName>xxx</DBName>
- </SQLSection>
- <ExportImageSection type="GilInterimStatsViewer.ExportImageSection, GilInterimStatsViewer">
- <ImageFormat>image/png</ImageFormat>
- <ImageCompression>100</ImageCompression>
- <ImageWidth>1280</ImageWidth>
- </ExportImageSection>
- </configuration>
|
J'ai créé les classes qui vont bien pour la lecture des paramètres des nouvelles sections:
Code :
- using System;
- using System.Configuration;
- using System.Xml;
- using System.Xml.Serialization;
- namespace GilInterimStatsViewer
- {
- public class SQLSection
- {
- private string ServerName_;
- private string DBName_;
- public string Server
- {
- get { return ServerName_; }
- set { ServerName_ = value; }
- }
- public string DBName
- {
- get { return DBName_; }
- set { DBName_ = value; }
- }
- }
- class SQLSectionHandler : IConfigurationSectionHandler
- {
- public object Create(object parent, object configContext, XmlNode section)
- {
- XmlSerializer xs = new XmlSerializer(typeof(SQLSection));
- XmlNodeReader xnr = new XmlNodeReader(section);
- return xs.Deserialize(xnr);
- }
- }
- }
|
J'arrive à lire correctement les valeurs:
Code :
- SQLSection sqlSect = (SQLSection)ConfigurationManager.GetSection("SQLSection" );
- string server = sqlSect.Server;
- string db = sqlSect.DBName;
|
Maintenant, problème, j'arrive à enregistrer de nouvelles valeurs pour ces sections personalisées...
Comment je dois faire?
J'ai essayé avec ça:
Code :
- Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
|
Mais je m'en sors pas pour le moment...
Qui peut me filer un petit coup de main?
Merci d'avance
Mike