弹来弹去跑马灯!

C# 读写App.config 配置文件

先要添加引用:System.Configuration

 

 //using System.Configuration;
            if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\app.config"))
            {
                MessageBox.Show("做不到App.config文件");
                return;
            }

            Configuration cfa = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (!cfa.AppSettings.Settings.AllKeys.Contains("msg"))
            {
                cfa.AppSettings.Settings.Add("msg", "" + DateTime.Now);
            }

            cfa.AppSettings.Settings["msg"].Value = "\"hi ##%&&&r的方式是的范德萨" + DateTime.Now + "hjj\"";
            cfa.Save();
            Title = cfa.AppSettings.Settings["msg"].Value;

 

另外app.config 编译生成后的名字前面会是  程序集文件名.exe.Config ,这个很烦,不知道谁有办法不用这个样子。

posted @ 2019-08-14 15:40  wgscd  阅读(1484)  评论(0)    收藏  举报