共用方式為


Configuration.SaveAs 方法

定義

將包含在這個 Configuration 物件中的組態設定寫入至指定的 XML 組態檔。

多載

SaveAs(String)

將包含在這個 Configuration 物件中的組態設定寫入至指定的 XML 組態檔。

SaveAs(String, ConfigurationSaveMode)

將包含在這個 Configuration 物件中的組態設定寫入至指定的 XML 組態檔。

SaveAs(String, ConfigurationSaveMode, Boolean)

將包含在這個 Configuration 物件中的組態設定寫入至指定的 XML 組態檔。

SaveAs(String)

來源:
Configuration.cs
來源:
Configuration.cs
來源:
Configuration.cs

將包含在這個 Configuration 物件中的組態設定寫入至指定的 XML 組態檔。

public:
 void SaveAs(System::String ^ filename);
public void SaveAs (string filename);
member this.SaveAs : string -> unit
Public Sub SaveAs (filename As String)

參數

filename
String

要儲存組態檔的路徑和檔案名稱。

例外狀況

無法寫入組態檔。

-或-

組態檔已經變更。

備註

方法 SaveAs 會保存自此 Configuration 物件建立至新檔案以來已修改的任何組態設定。

如果組態檔不存在於 所代表的實體位置

FilePath 屬性會建立新的組態檔,以包含與繼承組態不同的任何設定。

如果組態檔自建立此 Configuration 對象之後已變更,就會發生運行時錯誤。

適用於

SaveAs(String, ConfigurationSaveMode)

來源:
Configuration.cs
來源:
Configuration.cs
來源:
Configuration.cs

將包含在這個 Configuration 物件中的組態設定寫入至指定的 XML 組態檔。

public:
 void SaveAs(System::String ^ filename, System::Configuration::ConfigurationSaveMode saveMode);
public void SaveAs (string filename, System.Configuration.ConfigurationSaveMode saveMode);
member this.SaveAs : string * System.Configuration.ConfigurationSaveMode -> unit
Public Sub SaveAs (filename As String, saveMode As ConfigurationSaveMode)

參數

filename
String

要儲存組態檔的路徑和檔案名稱。

saveMode
ConfigurationSaveMode

ConfigurationSaveMode 值,決定所要儲存的屬性值。

例外狀況

無法寫入組態檔。

-或-

組態檔已經變更。

備註

方法會根據 saveMode 參數,將 SaveAs 物件中的Configuration組態設定保存到新的檔案。

如果組態檔不存在於 屬性所 FilePath 代表的實體位置,將會建立新的組態檔,以包含與繼承組態不同的任何設定。

如果組態檔自建立此 Configuration 對象之後已變更,就會發生運行時錯誤。

適用於

SaveAs(String, ConfigurationSaveMode, Boolean)

來源:
Configuration.cs
來源:
Configuration.cs
來源:
Configuration.cs

將包含在這個 Configuration 物件中的組態設定寫入至指定的 XML 組態檔。

public:
 void SaveAs(System::String ^ filename, System::Configuration::ConfigurationSaveMode saveMode, bool forceSaveAll);
public void SaveAs (string filename, System.Configuration.ConfigurationSaveMode saveMode, bool forceSaveAll);
member this.SaveAs : string * System.Configuration.ConfigurationSaveMode * bool -> unit
Public Sub SaveAs (filename As String, saveMode As ConfigurationSaveMode, forceSaveAll As Boolean)

參數

filename
String

要儲存組態檔的路徑和檔案名稱。

saveMode
ConfigurationSaveMode

ConfigurationSaveMode 值,決定所要儲存的屬性值。

forceSaveAll
Boolean

true 表示即使尚未修改組態仍要儲存,否則為 false

例外狀況

filename 為 null 或空字串 ("")。

範例

下列程式碼範例會示範如何使用 SaveAs 方法。


// Show how to use different modalities to save 
// a configuration file.
static void SaveConfigurationFile()
{
    try
    {

        // Get the current configuration file.
        System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None) as Configuration;

        // Save the full configuration file and force save even if the file was not modified.
        config.SaveAs("MyConfigFull.config", ConfigurationSaveMode.Full, true);
        Console.WriteLine("Saved config file as MyConfigFull.config using the mode: {0}",
            ConfigurationSaveMode.Full.ToString());

        config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None) as Configuration;

        // Save only the part of the configuration file that was modified. 
        config.SaveAs("MyConfigModified.config", ConfigurationSaveMode.Modified, true);
        Console.WriteLine("Saved config file as MyConfigModified.config using the mode: {0}",
            ConfigurationSaveMode.Modified.ToString());

        config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None) as Configuration;

        // Save the full configuration file.
        config.SaveAs("MyConfigMinimal.config");
        Console.WriteLine("Saved config file as MyConfigMinimal.config using the mode: {0}",
            ConfigurationSaveMode.Minimal.ToString());
    }
    catch (ConfigurationErrorsException err)
    {
        Console.WriteLine("SaveConfigurationFile: {0}", err.ToString());
    }
}

' Show how to use different modalities to save 
' a configuration file.
Public Shared Sub SaveConfigurationFile()
    Try

        ' Get the current configuration file.
        Dim config As System.Configuration.Configuration = TryCast(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None), Configuration)

        ' Save the full configuration file and force save even if the file was not modified.
        config.SaveAs("MyConfigFull.config", ConfigurationSaveMode.Full, True)
        Console.WriteLine("Saved config file as MyConfigFull.config using the mode: {0}", ConfigurationSaveMode.Full.ToString())

        config = TryCast(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None), Configuration)

        ' Save only the part of the configuration file that was modified. 
        config.SaveAs("MyConfigModified.config", ConfigurationSaveMode.Modified, True)
        Console.WriteLine("Saved config file as MyConfigModified.config using the mode: {0}", ConfigurationSaveMode.Modified.ToString())

        config = TryCast(ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None), Configuration)

        ' Save the full configuration file.
        config.SaveAs("MyConfigMinimal.config")
        Console.WriteLine("Saved config file as MyConfigMinimal.config using the mode: {0}", ConfigurationSaveMode.Minimal.ToString())

    Catch err As ConfigurationErrorsException
        Console.WriteLine("SaveConfigurationFile: {0}", err.ToString())
    End Try

End Sub

備註

方法會SaveAs根據 saveModeforceSaveAll 參數,將物件中的Configuration組態設定保存到新的檔案。

如果組態檔不存在於 屬性所 FilePath 代表的實體位置,將會建立新的組態檔,以包含與繼承組態不同的任何設定。

如果組態檔自建立此 Configuration 對象之後已變更,就會發生運行時錯誤。

適用於