Configuration.Save 方法 
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将包含在此 Configuration 对象中的配置设置写入当前 XML 配置文件。
重载
| Save() | 
						 将包含在此 Configuration 对象中的配置设置写入当前 XML 配置文件。  | 
        	
| Save(ConfigurationSaveMode) | 
						 将包含在此 Configuration 对象中的配置设置写入当前 XML 配置文件。  | 
        	
| Save(ConfigurationSaveMode, Boolean) | 
						 将包含在此 Configuration 对象中的配置设置写入当前 XML 配置文件。  | 
        	
Save()
- Source:
 - Configuration.cs
 
- Source:
 - Configuration.cs
 
- Source:
 - Configuration.cs
 
将包含在此 Configuration 对象中的配置设置写入当前 XML 配置文件。
public:
 void Save();
	public void Save ();
	member this.Save : unit -> unit
	Public Sub Save ()
	例外
注解
方法 Save 保留自创建此 Configuration 对象以来已修改的任何配置设置。 如果配置文件不存在于 属性表示 FilePath 的物理位置,则会创建一个新的配置文件,以包含与继承的配置不同的任何设置。
如果配置文件自创建此 Configuration 对象以来已更改,则会发生运行时错误。
注意
当包含配置文件的目录的 ACL (访问控制 List) 中列出“Creator Owner”时,的当前用户Save将成为文件的新所有者,并继承授予“Creator Owner”的权限。 这会导致当前用户的权限提升,并且删除了前一个所有者的权限。
适用于
Save(ConfigurationSaveMode)
- Source:
 - Configuration.cs
 
- Source:
 - Configuration.cs
 
- Source:
 - Configuration.cs
 
将包含在此 Configuration 对象中的配置设置写入当前 XML 配置文件。
public:
 void Save(System::Configuration::ConfigurationSaveMode saveMode);
	public void Save (System.Configuration.ConfigurationSaveMode saveMode);
	member this.Save : System.Configuration.ConfigurationSaveMode -> unit
	Public Sub Save (saveMode As ConfigurationSaveMode)
	参数
- saveMode
 - ConfigurationSaveMode
 
一个 ConfigurationSaveMode 值,该值用于确定要保存的属性值。
例外
示例
下面的代码示例演示如何使用 Save 方法保存自定义节。
// Show how to create an instance of the Configuration class
// that represents this application configuration file.  
static void CreateConfigurationFile()
{
    try
    {
        // Create a custom configuration section.
        CustomSection customSection = new CustomSection();
        // Get the current configuration file.
        System.Configuration.Configuration 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);
        }
        // Create and add an entry to appSettings section.
        
        string conStringname="LocalSqlServer";
        string conString = @"data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true";
        string providerName="System.Data.SqlClient";
        ConnectionStringSettings connStrSettings = new ConnectionStringSettings();
        connStrSettings.Name = conStringname;
        connStrSettings.ConnectionString= conString;
        connStrSettings.ProviderName = providerName;
        config.ConnectionStrings.ConnectionStrings.Add(connStrSettings);
        
        // Add an entry to appSettings section.
        int appStgCnt =
            ConfigurationManager.AppSettings.Count;
        string newKey = "NewKey" + appStgCnt.ToString();
        string newValue = DateTime.Now.ToLongDateString() +
          " " + DateTime.Now.ToLongTimeString();
        config.AppSettings.Settings.Add(newKey, newValue);
        // Save the configuration file.
        customSection.SectionInformation.ForceSave = true;
        config.Save(ConfigurationSaveMode.Full);
        Console.WriteLine("Created configuration file: {0}",
            config.FilePath);
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine("CreateConfigurationFile: {0}", err.ToString());
    }
}
' Show how to create an instance of the Configuration class
' that represents this application configuration file.  
Public Shared Sub CreateConfigurationFile()
    Try
        ' Create a custom configuration section.
        Dim customSection As New CustomSection()
        ' Get the current configuration file.
        Dim config As System.Configuration.Configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None)
        ' Create the section entry  
        ' in <configSections> and the 
        ' related target section in <configuration>.
        If config.Sections("CustomSection") Is Nothing Then
            config.Sections.Add("CustomSection", customSection)
        End If
        ' Create and add an entry to appSettings section.
        Dim conStringname As String = "LocalSqlServer"
        Dim conString As String = "data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true"
        Dim providerName As String = "System.Data.SqlClient"
        Dim connStrSettings As New ConnectionStringSettings()
        connStrSettings.Name = conStringname
        connStrSettings.ConnectionString = conString
        connStrSettings.ProviderName = providerName
        config.ConnectionStrings.ConnectionStrings.Add(connStrSettings)
        ' Add an entry to appSettings section.
        Dim appStgCnt As Integer = ConfigurationManager.AppSettings.Count
        Dim newKey As String = "NewKey" & appStgCnt.ToString()
        Dim newValue As String = Date.Now.ToLongDateString() & " " & Date.Now.ToLongTimeString()
        config.AppSettings.Settings.Add(newKey, newValue)
        ' Save the configuration file.
        customSection.SectionInformation.ForceSave = True
        config.Save(ConfigurationSaveMode.Full)
        Console.WriteLine("Created configuration file: {0}", config.FilePath)
    Catch err As ConfigurationErrorsException
        Console.WriteLine("CreateConfigurationFile: {0}", err.ToString())
    End Try
End Sub
    	注解
方法Save基于 saveMode 参数在 对象中Configuration保留配置设置。
如果配置文件不存在于 属性表示 FilePath 的物理位置,则会创建一个新的配置文件,以包含与继承的配置不同的任何设置。
如果配置文件自创建此 Configuration 对象以来已更改,则会发生运行时错误。
注意
当包含配置文件的目录的 ACL (访问控制 List) 中列出“Creator Owner”时,的当前用户Save将成为文件的新所有者,并继承授予“Creator Owner”的权限。 这会导致当前用户的权限提升,并且删除了前一个所有者的权限。
适用于
Save(ConfigurationSaveMode, Boolean)
- Source:
 - Configuration.cs
 
- Source:
 - Configuration.cs
 
- Source:
 - Configuration.cs
 
将包含在此 Configuration 对象中的配置设置写入当前 XML 配置文件。
public:
 void Save(System::Configuration::ConfigurationSaveMode saveMode, bool forceSaveAll);
	public void Save (System.Configuration.ConfigurationSaveMode saveMode, bool forceSaveAll);
	member this.Save : System.Configuration.ConfigurationSaveMode * bool -> unit
	Public Sub Save (saveMode As ConfigurationSaveMode, forceSaveAll As Boolean)
	参数
- saveMode
 - ConfigurationSaveMode
 
一个 ConfigurationSaveMode 值,该值用于确定要保存的属性值。
- forceSaveAll
 - Boolean
 
如果在未修改配置的情况下保存配置,则为 true;否则,为 false。
例外
注解
方法Save基于 saveMode 和 forceSaveAll 参数在 对象中Configuration保留配置设置。
如果配置文件不存在于 属性表示 FilePath 的物理位置,则会创建一个新的配置文件,以包含与继承的配置不同的任何设置。
如果配置文件自创建此 Configuration 对象以来已更改,则会发生运行时错误。
注意
当包含配置文件的目录的 ACL (访问控制 List) 中列出“Creator Owner”时,的当前用户Save将成为文件的新所有者,并继承授予“Creator Owner”的权限。 这会导致当前用户的权限提升,并且删除了前一个所有者的权限。