--
重點在:
下列範例會建立包含
ConfigurationManager.RefreshSection("appSettings")
Public Shared Sub Main(ByVal args() As String)
' Get the count of the Application Settings.
Dim appStgCnt As Integer = ConfigurationManager.AppSettings.Count
Dim asName As String = "AppStg" + appStgCnt.ToString()
' Get the configuration file.
Dim config As System.Configuration.Configuration = _
ConfigurationManager.OpenExeConfiguration( _
ConfigurationUserLevel.None)
' Add an Application setting.
config.AppSettings.Settings.Add(asName, _
DateTime.Now.ToLongDateString() + " " + _
DateTime.Now.ToLongTimeString())
' Save the configuration file.
config.Save(ConfigurationSaveMode.Modified)
' Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings")
Console.WriteLine()
Console.WriteLine("Application Settings:")
ShowAppSettings()
Console.WriteLine()
Console.WriteLine("Press 'Enter' to exit.")
Console.ReadLine()
End Sub 'Main
詳細請參考MSDN
--
相信很多人都被這 app.config 困擾,為何要關閉再啟動一次才生效的問題!
沒有留言:
張貼留言