C# 작업 프로필 (1)

1133 단어 config
.net 아래의 프로필은 두 가지로 나뉘는데 하나는 응용 프로그램 프로필이고 하나는 웹 프로그램 프로필이다.C# 구성 파일을 작업할 때 Configuration Manager를 사용하여 구성 파일을 관리합니다.
질의 구성 파일
ConfigurationManager를 사용합니다.AppSettions는 키에 따라 해당하는value 가져오기
string value=ConfigurationManager.AppSettings["test"];  //test key 

프로파일 업데이트, 추가
        public static bool SetConfig(string key, string value)
        {
            try
            {
                Configuration conf = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

                if (!conf.AppSettings.Settings.AllKeys.Contains(key))  //            key
                {
                    conf.AppSettings.Settings.Add(key, value); //  
                }
                else
                {
                    conf.AppSettings.Settings[key].Value = value; //  
                    conf.Save();
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }

요약:
또한 프로파일 작업은 XmlDocument을 사용하여 수행할 수 있습니다.다음에 총결산을 하겠습니다.

좋은 웹페이지 즐겨찾기