如何读取配置文件app.config里的一个表DataTable   读取得存储,有现成的方法吗

解决方案 »

  1.   

    Technically, App.config is read only in running time, you can't save data back. If you just wanna look up the datatable from app.config. You can write your handler implemented IconfigurationSectionHandler. see here
      

  2.   

    sorry, my bad. I guess you can write data on app.config by certain methods. Here is the link. Good luck.
      

  3.   

    我知道app.config运行时不能改变,那么我就想在app.config 存储一些xml数据
    <?xml version="1.0" encoding="utf-8" ?> 
    <Manager> 
           <IBody>Strong</IBody> 
           <IRoomSkill>FixRoom</IRoomSkill> 
    </Manager> 
    这些数据该如何读,要使用读取xml方法去读吗
      

  4.   

    step 1. create your handler and Manager classpublic class MyConfigHandler:IConfigurationSectionHandler
    {
        public MyConfigHandler(){}    public object Create(object parent, 
               object configContext, System.Xml.XmlNode section)
        {
            Manager mgt =new Manager();
            mgt.IBody= section.SelectSingleNode("IBody").InnerText;
            mgt.IRoomSkill= section.SelectSingleNode("IRoomSkill").InnerText;
            return mgt;
        }
    }public class Manager
    {
      private string _ibody;
      public string IBody
      {
        get { return this._ibody; }
        set { this._ibody = value; }
      }  private string _iRoomSkill;
      public string IRoomSkill
      {
        get { return this._iRoomSkill; }
        set { this._iRoomSkill = value; }
      }
    }step 2. in your App.config<configSections>
        ...
        <sectionGroup name="ManagerInfo">
        <section name="Manager" 
                type="ConfigSections.MyConfigHandler,ConfigSections"/>
        </sectionGroup></configSections><ManagerInfo>
       <Manager>   
           <IBody> Strong </IBody>   
           <IRoomSkill> FixRoom </IRoomSkill>   
      </Manager>   </ManagerInfo>step3. to read Manager from app.config in your codes, you needManager obj=(Manager)ConfigurationSettings.GetConfig("ManagerInfo/Manager");Good luck!