Salut à tous,

j'ai un souci concernant les fichiers de configuration.

J'ai le fichier de config suivant:

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<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 : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
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 : Sélectionner tout - Visualiser dans une fenêtre à part
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