在web里和win程序里如何调用自己的配置文件?请达人解惑

解决方案 »

  1.   

    1.
    ConfigurationSettings.AppSettings ["CollectCycle"];
    2.
    NameValueCollection nvc = (NameValueCollection) ConfigurationSettings.GetConfig("TempFolder");
    if(nvc["TempFolder"] != null && nvc["TempFolder"] != "")
    filePath = nvc["TempFolder"];
      

  2.   

    有几个API函数...
    [App setting]   ............这是Section
    Name = App      ............这是Setting, Key="Name", value = "App"
    Author = ChenMoZhiLang;
    ...GetPrivateProfileInt();
    GetPrivateProfileString();
    GetPrivateProfileSection();
    WritePrivateProfileSection();
    WritePrivateProfileString();
    GetPrivateProfileSectionNames();
    使用方法
      

  3.   

    //读取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 size, string filePath);
      

  4.   

    protected static string strConn=ConfigurationSettings.AppSettings["lucida.ConnectionString"];在CS文件里调用上面的 
    lucida.ConnectionString
    在WEB。CONFIG
      

  5.   

    读取web.config 或者 app.config中自定义配置的值的属性,常用2种方法.假设有如下配置:<appSettings> 
    <add key="A" value="config with A"/> 
    <add key="B" value="config with B"/> 
    </appSettings> using System.Configuration;[A] 方法string strTest  = ConfigurationSettings.AppSettings["A"];  // get A 's value[B] 方法AppSettingsReader appReader = new AppSettingsReader();
    string strTest = appReader.GetValue(strKey,typeof(string)).ToString();e.g.private string GetConfig(string strKey)
    {
    AppSettingsReader appReader = new AppSettingsReader();
    string strReturn;
    try
    {
    strReturn = appReader.GetValue(strKey,typeof(string)).ToString();
    }
    catch(Exception ex)
    {
    strReturn = ex.Message.ToString();
    }
    finally
    {
    appReader = null;
        
    }
    return strReturn;
    }