當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。