Created
July 8, 2020 13:23
-
-
Save facebookegypt/a066e94c7485619049e6cd1f6469e5f9 to your computer and use it in GitHub Desktop.
Create app.config file , Set config Value, Get Config value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Configuration | |
Imports System.Reflection | |
Public Class MyConfigs | |
Private _config As Configuration | |
Private _settings As AppSettingsSection | |
Public Function GetProperty(propertyName As String) As String | |
Return _settings.Settings.Item(propertyName).Value | |
End Function | |
Public Sub SetProperty(propertyName As String, propertyValue As String) | |
_settings.Settings.Item(propertyName).Value = propertyValue | |
End Sub | |
Public Sub New() | |
_config = ConfigurationManager.OpenExeConfiguration(Assembly.GetEntryAssembly().Location) | |
_settings = _config.AppSettings | |
End Sub | |
Protected Overrides Sub Finalize() | |
MyBase.Finalize() | |
_config.Save(ConfigurationSaveMode.Modified) | |
End Sub | |
End Class | |
'How to create config from Form | |
Public Class MainForm | |
Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load | |
Dim _appConfig As New AppConfig | |
_appConfig.SetProperty(propertyName, propertyValue) | |
_appConfig.GetProperty(propertyName) | |
End Sub | |
End Class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment