.数据表配置
Server=.
User=sa
PassWord=1234
DB=yesstar
tablename=SI_MESSAGE.链接URL
urlget_send=http://www.smsadmin.cn/smseting/wwwroot/api/get_send/?.帐号
SMSUid=qi2n2uis
.密码
SMSPwd= 122256.是否打印日志 0为打印 1为不打印
ifprintlog=0
---------------------------------------------------------
winform程序
需要读取配置文件,以上为参考.
句号开头为注释,可忽略.
其他字段都要对应读取出来,赋值给文本框。只取等于号之后的.要区别开来,需要这么弄各位大哥。现在的问题是在区别注释与不注释、怎么取相应的值。。

解决方案 »

  1.   

    using (TextReader tr = new StreamReader(<路径>))
                {
                    string eachLine = tr.ReadLine();
                    while (eachLine != null)
                    {
                         if ((eachLine.StartsWith("."))
                            continue;                    string[] splittedLine = eachLine.Split(new char[] { '=' });
                        
                        splittedLine[0]是key
                        splittedLine[1]是value                    eachLine = tr.ReadLine();
                    }
                }代码没有经过编译,可能有些许错误。
      

  2.   

     using System.Runtime.InteropServices; /// <summary>
        /// 读取,写入INI文件
        /// </summary>
        public static  class InitOperation
        {
            #region Win32 api declare
            //写INI文件
          [DllImport("kernel32")]
          private  static extern bool WritePrivateProfileString ( string section ,string key , string val , string filePath ); 
          //读ini文件(字符      [DllImport ("kernel32")]
          private  static extern int GetPrivateProfileString ( string section ,string key , string def , StringBuilder retVal ,int size , string filePath ) ;       //读ini文件(数字      [DllImport ("kernel32")]
          private  static extern int GetPrivateProfileInt( string section ,string key , int def , string filePath ) ;
            #endregion
            #region Public Method
            public static string IniReadValue(string Section, string Key,string FilePath)
            {
                StringBuilder sb = new StringBuilder(500);
                GetPrivateProfileString(Section, Key, "无法读取数据!", sb, 500, FilePath);
                return sb.ToString();
            }
            public static  bool IniWriteValue(string Section, string Key, string KeyValue, string FilePath)
            {
                return WritePrivateProfileString(Section, Key, KeyValue, FilePath);        }
            #endregion
        }InitOperation.IniReadValue(".数据表配置", "Server=.", ini文件路径);

    InitOperation.IniWriteValue(".数据表配置", "Server=.",写入的值, ini文件路径);
      

  3.   

    ini文件格式如下[数据表配置]
    Server=.
    User=sa读
    InitOperation.IniReadValue("数据表配置", "Server", ini文件路径);

    InitOperation.IniWriteValue("数据表配置", "Server",写入的值, ini文件路径);
      

  4.   

    这样乱糟糟的配置文件,还不如用 xxx.exe.config来处理好.直接就可以读取。
      

  5.   

    3搂朋友,等下我就试试。谢谢了5搂的便宜能详细说下么?你是说用web.config??因为我这个配置文件很乱的,以后会加很多 配置的项。
    比如:数据库字段等等。
      

  6.   

    以前我也想你这样写,后来我改成XML了
      

  7.   

    配置项太多.XML怕不方便  还要写<DB>1111<DB>这样的那位大哥有现成的哈 呵呵 比较懒
      

  8.   

    为何不用App.configkey value  不比你这个来的快。
      

  9.   

    有一个easyconfig,我过去弄wince程序时用过那个,将那个编译了一个wince可用的版本,当然win的版本也有,可以直接读取ini文件,并且功能比较强大,有一个bug,过去弄的时候修复了,刚问朋友要到源码了,是个开源项目,可以尝试下
    在网上找,那个项目地址居然没有下载链接了。如需要,pm我,或者留下邮箱
      

  10.   

    你那个配置文件格式可以改成其他形式吗?类似ini形式的,可以使用easyconfig处理,如觉得可以,pm我或者留下邮箱。
    下面这种模式可以读取[Video]
    Fullscreen = true
    Width = 1280
    Height = 720[Level1]
    NumberOfEnemies=2000
    Lives =              10
    Timer                =                 999
    EnemyNames = "Steve",          "Sam",                "Bill"
    EnemyGuns = 13, 28, 43, 499
    CanShoot = true, yes, on, no, false, off
      

  11.   

    即使出于某种考虑不使用App.Config或Web.Config,为什么也不考虑用个xml呢?读写的方法都是现成的。自己解析的话比较麻烦,基本上就是读取每一行,如果不是空,并且不是以预定义的注释符开头的话,拆分等号两边的字串,然后看看左边是否是个预期的值,是的话认为是个key,等号右边的部分就是它的值。
      

  12.   

    easyconfig(.net读取ini文件开源项目,支持windows和wince(wince是自己开发wince时修改的,原来的只支持.net,不支持.net cf))
    含有一个示例,下载地址如下(今天叫以前的同事从vss源码服务器上下载下来的,是vs2005的项目,还没有取消源代码支持,直接发上来了,不过是可以用的,我自己修改了一个bug——string类型不支持“.”符号的bug):
    http://download.csdn.net/source/3091986
    那个功能是很强大的ini文件读取库,你下下来就知道了。
      

  13.   

    easyconfig是基于mit许可的,是个很宽松的许可:
    MIT許可證 (The MIT License)是許多軟體 授權條 款中,被廣泛使用的其中一種。與其他常見的軟體授權條款(如GPL 、LPGL 、BSD)相比,MIT是相對寬鬆的 軟體授權條款。簡介
    MIT許可證之名源自麻省理工學院(Massachusetts Institute of Technology, MIT),又稱「X條款」(X License)或「X11條款」(X11 License)MIT內容與三條款BSD許可證 (3-clause BSD license)內容頗為近似,但是賦予軟體被授權人更大的權利與更少的限制。運 用情形
    有許多團體均採用MIT許可證。例如著名的ssh 連線軟體PuTTY與X Windows System (X11)即為例子。Expat, Mono開發平台函式庫,Ruby on Rails, Lua 5.0 onwards等等也都採用MIT授權條款。條款內容
    被授權人權利
    被授權人有權利使用、復製、修改、合併、出版發行、散布、再授權及販售軟體及軟體的副本。被授權人可根據程式的需要修改授權條款為適當的內容。被授權人義務
    在軟體和軟體的所有副本中都必須包含版權聲明和許可聲明。其他重要特性
    此授權條款並非屬copyleft的自由軟體授權條款,允許在自由/開放源碼軟體 或非自由軟體(proprietary software)所使用。MIT的內容可依照程式著作權者的需求更改內容。此亦為MIT與BSD (The BSD license, 3-clause BSD license)本質上不同處。MIT條款可與其他授權條款並存。另外,MIT條款也是自由軟體基金會(FSF)所認可的自由軟體授權條款,與G P L 相 容。英文原文:Open Source Initiative OSI - The MIT License:LicensingThe MIT LicenseCopyright (c) <year> <copyright holders>Permission is hereby granted, free of charge, to any person obtaining a copy
    of this software and associated documentation files (the "Software"), to deal
    in the Software without restriction, including without limitation the rights
    to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    copies of the Software, and to permit persons to whom the Software is
    furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in
    all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    THE SOFTWARE.
      

  14.   

    easyconfig 下载地址:http://download.csdn.net/source/3091986
      

  15.   

    using System.Runtime.InteropServices; /// <summary>
      /// 读取,写入INI文件
      /// </summary>
      public static class InitOperation
      {
      #region Win32 api declare
      //写INI文件
       [DllImport("kernel32")]
       private static extern bool WritePrivateProfileString ( string section ,string key , string val , string filePath );  
       //读ini文件(字符   [DllImport ("kernel32")]
       private static extern int GetPrivateProfileString ( string section ,string key , string def , StringBuilder retVal ,int size , string filePath ) ;     //读ini文件(数字   [DllImport ("kernel32")]
       private static extern int GetPrivateProfileInt( string section ,string key , int def , string filePath ) ;
      #endregion
      #region Public Method
      public static string IniReadValue(string Section, string Key,string FilePath)
      {
      StringBuilder sb = new StringBuilder(500);
      GetPrivateProfileString(Section, Key, "无法读取数据!", sb, 500, FilePath);
      return sb.ToString();
      }
      public static bool IniWriteValue(string Section, string Key, string KeyValue, string FilePath)
      {
      return WritePrivateProfileString(Section, Key, KeyValue, FilePath);  }
      #endregion
      }InitOperation.IniReadValue(".数据表配置", "Server=.", ini文件路径);

    InitOperation.IniWriteValue(".数据表配置", "Server=.",写入的值, ini文件路径);
      

  16.   

    楼上的  [DllImport("kernel32")]
    是什么?
    谢谢!!!!