Configuration.Save メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
この Configuration オブジェクトに含まれる構成設定を現在の XML 構成ファイルに書き込みます。
オーバーロード
| 名前 | 説明 |
|---|---|
| Save() |
この Configuration オブジェクトに含まれる構成設定を現在の XML 構成ファイルに書き込みます。 |
| Save(ConfigurationSaveMode) |
この Configuration オブジェクトに含まれる構成設定を現在の XML 構成ファイルに書き込みます。 |
| Save(ConfigurationSaveMode, Boolean) |
この Configuration オブジェクトに含まれる構成設定を現在の XML 構成ファイルに書き込みます。 |
Save()
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
この Configuration オブジェクトに含まれる構成設定を現在の XML 構成ファイルに書き込みます。
public:
void Save();
public void Save();
member this.Save : unit -> unit
Public Sub Save ()
例外
注釈
Save メソッドは、このConfiguration オブジェクトの作成以降に変更されたすべての構成設定を保持します。 FilePath プロパティによって表される物理的な場所に構成ファイルが存在しない場合は、継承された構成とは異なる設定を含む新しい構成ファイルが作成されます。
この Configuration オブジェクトの作成後に構成ファイルが変更された場合は、実行時エラーが発生します。
注
構成ファイルを含むディレクトリの ACL (アクセス制御リスト) に "Creator Owner" が表示されている場合、 Save の現在のユーザーはファイルの新しい所有者になり、"Creator Owner" に付与されたアクセス許可を継承します。 これにより、現在のユーザーの特権が昇格され、前の所有者の特権が削除されます。
適用対象
Save(ConfigurationSaveMode)
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- 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 (アクセス制御リスト) に "Creator Owner" が表示されている場合、 Save の現在のユーザーはファイルの新しい所有者になり、"Creator Owner" に付与されたアクセス許可を継承します。 これにより、現在のユーザーの特権が昇格され、前の所有者の特権が削除されます。
適用対象
Save(ConfigurationSaveMode, Boolean)
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- Configuration.cs
- ソース:
- 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 (アクセス制御リスト) に "Creator Owner" が表示されている場合、 Save の現在のユーザーはファイルの新しい所有者になり、"Creator Owner" に付与されたアクセス許可を継承します。 これにより、現在のユーザーの特権が昇格され、前の所有者の特権が削除されます。