Configuration.Save Methode
Definitie
Belangrijk
Bepaalde informatie heeft betrekking op een voorlopige productversie die aanzienlijk kan worden gewijzigd voordat deze wordt uitgebracht. Microsoft biedt geen enkele expliciete of impliciete garanties met betrekking tot de informatie die hier wordt verstrekt.
Hiermee schrijft u de configuratie-instellingen in dit Configuration object naar het huidige XML-configuratiebestand.
Overloads
| Name | Description |
|---|---|
| Save() |
Hiermee schrijft u de configuratie-instellingen in dit Configuration object naar het huidige XML-configuratiebestand. |
| Save(ConfigurationSaveMode) |
Hiermee schrijft u de configuratie-instellingen in dit Configuration object naar het huidige XML-configuratiebestand. |
| Save(ConfigurationSaveMode, Boolean) |
Hiermee schrijft u de configuratie-instellingen in dit Configuration object naar het huidige XML-configuratiebestand. |
Save()
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
Hiermee schrijft u de configuratie-instellingen in dit Configuration object naar het huidige XML-configuratiebestand.
public:
void Save();
public void Save();
member this.Save : unit -> unit
Public Sub Save ()
Uitzonderingen
Het configuratiebestand kan niet worden geschreven naar.
– of –
Het configuratiebestand is gewijzigd.
Opmerkingen
De Save methode behoudt alle configuratie-instellingen die zijn gewijzigd sinds dit Configuration object is gemaakt. Als er geen configuratiebestand bestaat op de fysieke locatie die wordt vertegenwoordigd door de FilePath eigenschap, wordt er een nieuw configuratiebestand gemaakt dat instellingen bevat die afwijken van de overgenomen configuratie.
Als het configuratiebestand is gewijzigd sinds dit Configuration object is gemaakt, treedt er een runtimefout op.
Note
Wanneer 'Eigenaar van maker' wordt vermeld in de ACL (Access Control Lijst) van de map met het configuratiebestand, wordt de huidige gebruiker van Save de nieuwe eigenaar van het bestand en neemt de machtigingen over die zijn verleend aan 'Maker-eigenaar'. Dit resulteert in uitbreiding van bevoegdheden voor de huidige gebruiker en het verwijderen van bevoegdheden voor de vorige eigenaar.
Van toepassing op
Save(ConfigurationSaveMode)
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
Hiermee schrijft u de configuratie-instellingen in dit Configuration object naar het huidige XML-configuratiebestand.
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)
Parameters
- saveMode
- ConfigurationSaveMode
Een ConfigurationSaveMode waarde die bepaalt welke eigenschapswaarden moeten worden opgeslagen.
Uitzonderingen
Het configuratiebestand kan niet worden geschreven naar.
– of –
Het configuratiebestand is gewijzigd.
Voorbeelden
In het volgende codevoorbeeld ziet u hoe u de Save methode gebruikt om een aangepaste sectie op te slaan.
// 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
Opmerkingen
De Save methode behoudt configuratie-instellingen in het Configuration object op basis van de saveMode parameter.
Als er geen configuratiebestand bestaat op de fysieke locatie die wordt vertegenwoordigd door de FilePath eigenschap, wordt er een nieuw configuratiebestand gemaakt dat instellingen bevat die afwijken van de overgenomen configuratie.
Als het configuratiebestand is gewijzigd sinds dit Configuration object is gemaakt, treedt er een runtimefout op.
Note
Wanneer 'Eigenaar van maker' wordt vermeld in de ACL (Access Control Lijst) van de map met het configuratiebestand, wordt de huidige gebruiker van Save de nieuwe eigenaar van het bestand en neemt de machtigingen over die zijn verleend aan 'Maker-eigenaar'. Dit resulteert in uitbreiding van bevoegdheden voor de huidige gebruiker en het verwijderen van bevoegdheden voor de vorige eigenaar.
Van toepassing op
Save(ConfigurationSaveMode, Boolean)
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
- Bron:
- Configuration.cs
Hiermee schrijft u de configuratie-instellingen in dit Configuration object naar het huidige XML-configuratiebestand.
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)
Parameters
- saveMode
- ConfigurationSaveMode
Een ConfigurationSaveMode waarde die bepaalt welke eigenschapswaarden moeten worden opgeslagen.
- forceSaveAll
- Boolean
true om op te slaan, zelfs als de configuratie niet is gewijzigd; anders, false.
Uitzonderingen
Het configuratiebestand kan niet worden geschreven naar.
– of –
Het configuratiebestand is gewijzigd.
Opmerkingen
De Save methode behoudt configuratie-instellingen in het Configuration object op basis van de saveMode en forceSaveAll parameters.
Als er geen configuratiebestand bestaat op de fysieke locatie die wordt vertegenwoordigd door de FilePath eigenschap, wordt er een nieuw configuratiebestand gemaakt dat instellingen bevat die afwijken van de overgenomen configuratie.
Als het configuratiebestand is gewijzigd sinds dit Configuration object is gemaakt, treedt er een runtimefout op.
Note
Wanneer 'Eigenaar van maker' wordt vermeld in de ACL (Access Control Lijst) van de map met het configuratiebestand, wordt de huidige gebruiker van Save de nieuwe eigenaar van het bestand en neemt de machtigingen over die zijn verleend aan 'Maker-eigenaar'. Dit resulteert in uitbreiding van bevoegdheden voor de huidige gebruiker en het verwijderen van bevoegdheden voor de vorige eigenaar.