• 操作config文件


    Configuration objConfig = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.StartupPath + @"\TestConfig.exe");

    //需要有TestConfig.exe文件
                    ConnectionStringsSection objAppsettings = null;
                    objAppsettings = (ConnectionStringsSection)objConfig.GetSection("connectionStrings");
                    foreach (ConnectionStringSettings s in objAppsettings.ConnectionStrings)
                    {
                        Console.WriteLine(s.Name);
                        if (s.Name == "ConnectionString")
                        {
                            string ss;
                            if (s.LockItem == false)
                            {
                                ss = s.ConnectionString;
                                s.ConnectionString += " encrypt";
                                s.LockItem = true;
                                objConfig.Save(ConfigurationSaveMode.Modified);
                            }
                            else
                            {
                                ss = s.ConnectionString;

                            }
                            Console.WriteLine(ss);
                        }
                    }
                    Console.ReadKey();

                    if (!objAppsettings.SectionInformation.IsProtected)
                    {
                        objAppsettings.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
                        objAppsettings.SectionInformation.ForceSave = true;
                        objConfig.Save(ConfigurationSaveMode.Modified);
                    }
                    else
                    {
                        objAppsettings.SectionInformation.UnprotectSection();
                        objAppsettings.SectionInformation.ForceSave = true;
                        objConfig.Save(ConfigurationSaveMode.Modified);
                    }

  • 相关阅读:
    用 Web 实现一个简易的音频编辑器
    TypeScript教程
    他的独,殇情沉醉
    重新拎一遍js的正则表达式
    网络流
    Xmind最新的安装与破解教程
    adb的端口号5037被占用的解决方法
    使用Fiddler模拟弱网测试教程
    web的前台、后台、前端、后端
    常见面试笔试题
  • 原文地址:https://www.cnblogs.com/djian/p/1922698.html
Copyright © 2020-2023  润新知