zoukankan      html  css  js  c++  java
  • 操作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);
                    }

  • 相关阅读:
    (一)python 简单网页爬虫
    环形队列的应用
    AutoResetEvent 和 ManualResetEvent 多线程应用
    委托 和 事件
    Action 和 Func 的用法以及区别
    IIS 配置缓存
    IIS 发布双证书
    函数中返回局部变量的问题
    python函数2-函数参数
    Python基础语法6-冒泡排序
  • 原文地址:https://www.cnblogs.com/djian/p/1922698.html
Copyright © 2011-2022 走看看