当前位置: 首页>>代码示例>>C#>>正文


C# Configuration.Save方法代码示例

本文整理汇总了C#中System.Configuration.Configuration.Save方法的典型用法代码示例。如果您正苦于以下问题:C# Configuration.Save方法的具体用法?C# Configuration.Save怎么用?C# Configuration.Save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Configuration.Configuration的用法示例。


在下文中一共展示了Configuration.Save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: UpdateAppSetting

 /// <summary>
 /// Sample 
 /// Configuration configuration = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
 /// </summary>
 /// <param name="configuration"></param>
 /// <param name="key"></param>
 /// <param name="value"></param>
 public static void UpdateAppSetting(Configuration configuration, string key, string value)
 {
     configuration.AppSettings.Settings[key].Value = value;
     configuration.AppSettings.SectionInformation.ForceSave = true;
     configuration.Save(ConfigurationSaveMode.Modified);
     ConfigurationManager.RefreshSection("appSettings");
 }
开发者ID:ZX10Tomcat,项目名称:PriceUploader,代码行数:14,代码来源:cAppConfig.cs

示例2: UserSettingsFrom

		/// <summary>
		/// Retrieves the current UserSettingsSection from the specified configuration, if none
		/// exists a new one is created.  If a previous version of the userSettings exists they
		/// will be copied to the UserSettingsSection.
		/// </summary>
		public static UserSettingsSection UserSettingsFrom(Configuration config)
		{
			UserSettingsSection settings = null;

			try { settings = (UserSettingsSection)config.Sections[SECTION_NAME]; }
			catch(InvalidCastException)
			{ config.Sections.Remove(SECTION_NAME); }

			if (settings == null)
			{
				settings = new UserSettingsSection();
				settings.SectionInformation.AllowExeDefinition = ConfigurationAllowExeDefinition.MachineToLocalUser;
				settings.SectionInformation.RestartOnExternalChanges = false;
				settings.SectionInformation.Type = String.Format("{0}, {1}", typeof(UserSettingsSection).FullName, typeof(UserSettingsSection).Assembly.GetName().Name);

				UpgradeUserSettings(config, settings);

				config.Sections.Add(SECTION_NAME, settings);
			}
			else if (!config.HasFile)
				UpgradeUserSettings(config, settings);

			if (settings.IsModified())
			{
				try { config.Save(); }
				catch (Exception e) { Trace.TraceError("{1}\r\n{0}", e, "Failed to save configuration."); }
			}

			return settings;
		}
开发者ID:hivie7510,项目名称:csharptest-net,代码行数:35,代码来源:UserSettingsSection.cs

示例3: GetConfiguration

 /// <summary>
 /// This method will retrieve the configuration settings.
 /// </summary>
 private void GetConfiguration()
 {
     try
     {
         m_config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
         if (m_config.Sections["TracePreferences"] == null)
         {
             m_settings = new TracePreferences();
             m_config.Sections.Add("TracePreferences", m_settings);
             m_config.Save(ConfigurationSaveMode.Full);
         }
         else
             m_settings = (TracePreferences)m_config.GetSection("TracePreferences");
     }
     catch (InvalidCastException e)
     {
         System.Diagnostics.Trace.WriteLine("Preference Error - " + e.Message, "MainForm.GetConfiguration");
         MessageBoxOptions options = 0;
         MessageBox.Show(Properties.Resources.PREF_NOTLOADED, Properties.Resources.PREF_CAPTION,
                     MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button1, options);
         m_settings = new TracePreferences();
     }
     catch (ArgumentException e)
     {
         System.Diagnostics.Trace.WriteLine("Argument Error - " + e.Message, "MainForm.GetConfiguration");
         throw;
     }
     catch (ConfigurationErrorsException e)
     {
         System.Diagnostics.Trace.WriteLine("Configuration Error - " + e.Message, "MainForm.GetConfiguration");
         throw;
     }
 }
开发者ID:killbug2004,项目名称:WSProf,代码行数:36,代码来源:StartupSettings.cs

示例4: UpdateConfig

 private static void UpdateConfig(Configuration config)
 {
     // Save the configuration file.
     config.Save(ConfigurationSaveMode.Modified, true);
     // Force a reload of a changed section.
     ConfigurationManager.RefreshSection("appSettings");
 }
开发者ID:martinskuta,项目名称:Nubot,代码行数:7,代码来源:AppSettings.cs

示例5: btnSubmit_Click

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Configuration = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
            //操作appSettings
            AppSettingsSection appseting = (AppSettingsSection)Configuration.GetSection("appSettings");      //修改设置
            try
            {
                appseting.Settings["txtiosapplink"].Value = this.txtiosapplink.Text;
            }
            catch (Exception)
            {

                appseting.Settings.Add("txtiosapplink", this.txtiosapplink.Text);
            }
            try
            {
                appseting.Settings["txtapklink"].Value = this.txtapklink.Text;
            }
            catch (Exception)
            {

                appseting.Settings.Add("txtapklink", this.txtapklink.Text);
            }
            Configuration.Save();
        }
开发者ID:lijiajin1987,项目名称:OfficialWebsite,代码行数:25,代码来源:Home.aspx.cs

示例6: CreateConnectionStringsConfig

        ///<summary> 
        ///创建ConnectionString(如果存在,先删除再创建) 
        ///</summary> 
        ///<param name="config">Configuration实例</param>
        ///<param name="newName">连接字符串名称</param> 
        ///<param name="newConString">连接字符串内容</param> 
        ///<param name="newProviderName">数据提供程序名称</param>         
        public static Boolean CreateConnectionStringsConfig(Configuration config, string newName, string newConString, string newProviderName)
        {
            if (config == null && string.IsNullOrEmpty(newName) && string.IsNullOrEmpty(newConString) && string.IsNullOrEmpty(newProviderName))
            {
                return false;
            }

            bool isModified = false;
            //记录该连接串是否已经存在
            //如果要更改的连接串已经存在
            if (config.ConnectionStrings.ConnectionStrings[newName] != null)
            { isModified = true; }

            //新建一个连接字符串实例
            ConnectionStringSettings mySettings = new ConnectionStringSettings(newName, newConString, newProviderName);

            // 如果连接串已存在,首先删除它
            if (isModified)
            {
                config.ConnectionStrings.ConnectionStrings.Remove(newName);
            }
            // 将新的连接串添加到配置文件中.
            config.ConnectionStrings.ConnectionStrings.Add(mySettings);
            // 保存对配置文件所作的更改
            config.Save(ConfigurationSaveMode.Modified);

            return true;
        }
开发者ID:riveryong,项目名称:shopsoft,代码行数:35,代码来源:ConfigFileUtil.cs

示例7: CrearArchivoConfig

 private static void CrearArchivoConfig()
 {
     XmlTextWriter.Create(Assembly.GetExecutingAssembly().Location + ".config");
     _config =
         ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
     _config.Save();
 }
开发者ID:Maharba,项目名称:YACM,代码行数:7,代码来源:ConfigAcciones.cs

示例8: ClearConfiguration

        /// <summary>
        /// Clears configuration (app.config) of all settings.
        /// </summary>
        /// <param name="config">Configuration to be cleared.</param>
        public static void ClearConfiguration(Configuration config)
        {
            for (int i = config.Sections.Count - 1; i >= 0; i--)
            {
                ConfigurationSection section = config.Sections[i];

                // Ensure that this section came from the file we provided and not elsewhere, such as machine.config
                if (section.SectionInformation.IsDeclared || (section.ElementInformation.Source != null && section.ElementInformation.Source.Equals(config.FilePath)))
                {
                    string parentSectionName = section.SectionInformation.GetParentSection().SectionInformation.SectionName;
                    config.Sections.RemoveAt(i);
                    config.Save(ConfigurationSaveMode.Full, false);
                    ConfigurationManager.RefreshSection(parentSectionName);
                }
            }
            config.Save(ConfigurationSaveMode.Full, false);
        }
开发者ID:uQr,项目名称:Visual-NHibernate,代码行数:21,代码来源:ConfigurationUtility.cs

示例9: Form1

        public Form1()
        {
            backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
            backgroundWorker2 = new System.ComponentModel.BackgroundWorker();
            backgroundWorker3 = new System.ComponentModel.BackgroundWorker();

            backgroundWorker2.WorkerReportsProgress = true;
            backgroundWorker2.WorkerSupportsCancellation = true;

            InitializeComponent();
            backgroundWorker1.DoWork +=
                new DoWorkEventHandler(backgroundWorker1_DoWork);
            backgroundWorker1.RunWorkerCompleted +=
                new RunWorkerCompletedEventHandler(
            backgroundWorker1_RunWorkerCompleted);
            backgroundWorker1.ProgressChanged +=
                new ProgressChangedEventHandler(
            backgroundWorker1_ProgressChanged);

            backgroundWorker2.DoWork +=
                new DoWorkEventHandler(backgroundWorker2_DoWork);
            backgroundWorker2.RunWorkerCompleted +=
                new RunWorkerCompletedEventHandler(
            backgroundWorker2_RunWorkerCompleted);
            backgroundWorker2.ProgressChanged +=
                new ProgressChangedEventHandler(
            backgroundWorker2_ProgressChanged);
            customSection = new CustomSection();
            try
            {
                // Get the current configuration file.
                config = ConfigurationManager.OpenExeConfiguration(
                        ConfigurationUserLevel.None);

                // Create the custom section entry
                // in <configSections> group and the
                // related target section in <configuration>.
                if (config.Sections["CustomSection"] == null)
                {
                    config.Sections.Add("CustomSection", customSection);

                    // Save the configuration file.
                    customSection.SectionInformation.ForceSave = true;
                    config.Save(ConfigurationSaveMode.Full);
                }
                customSection =
                     config.GetSection("CustomSection") as CustomSection;

                userText.Text = customSection.User;
                passwdText.Text = customSection.Passwd;
                databaseText.Text = customSection.Database;
            }
            catch (ConfigurationErrorsException err)
            {
                MessageBox.Show("CreateConfigurationFile: {0}", err.ToString());
            }
        }
开发者ID:gcgc100,项目名称:gittest,代码行数:57,代码来源:Form1.cs

示例10: ProtectSectionImpl

        private static void ProtectSectionImpl(string sectionName, string provider, Configuration config)
        {
            ConfigurationSection section = config.GetSection(sectionName);

            if (section != null && !section.SectionInformation.IsProtected)
            {
                section.SectionInformation.ProtectSection(provider);
                config.Save();
            }
        }
开发者ID:kevinmcfarlane,项目名称:ArcadiaTechnology.Tools,代码行数:10,代码来源:Encrypter.cs

示例11: UnprotectSectionImpl

        private static void UnprotectSectionImpl(string sectionName, Configuration config)
        {
            ConfigurationSection section = config.GetSection(sectionName);

            if (section != null && section.SectionInformation.IsProtected)
            {
                section.SectionInformation.UnprotectSection();
                config.Save();
            }
        }
开发者ID:kevinmcfarlane,项目名称:ArcadiaTechnology.Tools,代码行数:10,代码来源:Encrypter.cs

示例12: Reload

 public static void Reload()
 {
     Config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal);
     ConnectionStringsSection = Config.GetSection("userConnectionStrings") as System.Configuration.ConnectionStringsSection;
     if (ConnectionStringsSection == null)
     {
         ConnectionStringsSection = new System.Configuration.ConnectionStringsSection();
         ConnectionStringsSection.SectionInformation.set_AllowExeDefinition(ConfigurationAllowExeDefinition.MachineToLocalUser);
         Config.Sections.Add("userConnectionStrings", ConnectionStringsSection);
         Config.Save();
     }
 }
开发者ID:u4097,项目名称:SQLScript,代码行数:12,代码来源:ConnectionsConfigurator.cs

示例13: Config

        public Config(string configPath)
        {
            CreateConfigDir(configPath);

            var configFile = Path.Combine(configPath, "config.xml");

            _config = GetFileConfig(configFile);

            Init(_config);

            _config.Save(ConfigurationSaveMode.Modified);
        }
开发者ID:zerkms,项目名称:shary,代码行数:12,代码来源:Config.cs

示例14: SystemConfig

        static SystemConfig()
        {
            config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

            if (config.Sections["Machine"] == null)
            {
                config.Sections.Add("Machine", new MachineSection());
                machineSection.SectionInformation.ForceSave = true;
                config.Save();
            }
            machineSection = config.GetSection("Machine") as MachineSection;
        }
开发者ID:cryogen,项目名称:VM86CS,代码行数:12,代码来源:SystemConfig.cs

示例15: Set

        private static void Set(string property, string value, Configuration config)
        {
            if (config == null)
                return;

            var item = config.AppSettings.Settings[property];
            if (item == null)
                config.AppSettings.Settings.Add(new KeyValueConfigurationElement(property, value));
            else
                item.Value = value;

            config.Save();
        }
开发者ID:SorenHK,项目名称:sdb,代码行数:13,代码来源:ConfigurationHelper.cs


注:本文中的System.Configuration.Configuration.Save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。