我是一个.NET新手,遇到一个问题,想请教高手
如何读写.NET中的ini文档,如何创建ini文档?

解决方案 »

  1.   

    ini 文件 改放在web。config文件中了
      

  2.   

    使用这里的方式
    http://www.codeproject.com/csharp/readwritexmlini.asp
      

  3.   

    using System.Runtime.InteropServices ;//调用WindowsAPI时所要用的命名空间.
    //调用WindowsAPI函数来读取INI配置文件
    [DllImport("kernel32")]
    private static extern long WritePrivateProfileString(string section,
    string key,string val,string filePath);
    [DllImport("kernel32")]
    private static extern int GetPrivateProfileString(string section,string key,
    string def,StringBuilder retVal,int siae,string filePath);
    //读取配置文件
    public static int loadConfig(string path)
    {
    int sign=0; //设置返回值,用于判断读取配置文件是否出错
    StringBuilder temp = new StringBuilder(255);
    string FileName = path;//设置配置文件路径
    string section = "IP地址";//设置"段"的名称
    string key = "IP";//设置"关键字"的名称
    GetPrivateProfileString(section, key, "noValue", temp, 255, FileName) ;//读取"关键字"的值
    ip=temp.ToString ();
    if(ip=="noValue")//如果读取出错,返回出错
    {
    ip="";
    return sign; 
    }

    section="用户名";
    key="UserName";
    GetPrivateProfileString(section, key, "noValue", temp, 255, FileName) ;
    connectUsername=temp.ToString ();
    if(connectUsername=="noValue")
    {
    connectUsername="";
    return sign; 
    } section="密码";
    key="Password";
    GetPrivateProfileString(section, key, "noValue", temp, 255, FileName) ;
    connectPassword=temp.ToString ();
    if(connectPassword=="noValue")
    {
    connectPassword="";
    return sign; 
    }
    sign=1;
    return sign;
    } //保存配置文件
    public static void storageFile(string filePath,string ipaddress,string name,string password)
    {
    string FileName = filePath;
    string section = "IP地址";
    string key = "IP";   
    string keyValue=ipaddress;
    WritePrivateProfileString (section, key, keyValue, FileName);  

    section="用户名";
    key="UserName";
    keyValue=name;
    WritePrivateProfileString (section, key, keyValue, FileName); section="密码";
    key="Password";
    keyValue=password;
    WritePrivateProfileString (section, key, keyValue, FileName);
    }  }