System.Configuration.Configuration.Save C# (CSharp) Метод

Save() публичный Метод

public Save ( ConfigurationSaveMode mode, bool forceUpdateAll ) : void
mode ConfigurationSaveMode
forceUpdateAll bool
Результат void
		public void Save (ConfigurationSaveMode mode, bool forceUpdateAll)
		{
			ConfigurationSaveEventHandler saveStart = SaveStart;
			ConfigurationSaveEventHandler saveEnd = SaveEnd;
			
			object ctx = null;
			Exception saveEx = null;
			Stream stream = system.Host.OpenStreamForWrite (streamName, null, ref ctx);
			try {
				if (saveStart != null)
					saveStart (this, new ConfigurationSaveEventArgs (streamName, true, null, ctx));
				
				Save (stream, mode, forceUpdateAll);
				system.Host.WriteCompleted (streamName, true, ctx);
			} catch (Exception ex) {
				saveEx = ex;
				system.Host.WriteCompleted (streamName, false, ctx);
				throw;
			} finally {
				stream.Close ();
				if (saveEnd != null)
					saveEnd (this, new ConfigurationSaveEventArgs (streamName, false, saveEx, ctx));
			}
		}
		

Same methods

Configuration::Save ( ) : void
Configuration::Save ( ConfigurationSaveMode mode ) : void
Configuration::Save ( Stream stream, ConfigurationSaveMode mode, bool forceUpdateAll ) : void

Usage Example

Пример #1
0
        ///<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;
        }
All Usage Examples Of System.Configuration.Configuration::Save