I have several VB.NET projects that use the same application settings. They use the My.Settings object. I am not sure how to import application settings from one VB.NET project to another. What isa the best way to do that?
I have several VB.NET projects that use the same application settings. They use the My.Settings object. I am not sure how to import application settings from one VB.NET project to another. What isa the best way to do that?
Hi @MarcMenzel-8677 ,
Maybe you can use the code below to export/import settings.
Private Sub export_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles export.Click
Dim sDialog As New SaveFileDialog()
sDialog.DefaultExt = ".AppSettings"
sDialog.Filter = "Application Settings (*.AppSettings)|*AppSettings"
If sDialog.ShowDialog() = DialogResult.OK Then
Using sWriter As New StreamWriter(sDialog.FileName)
For Each setting As Configuration.SettingsPropertyValue In My.Settings.PropertyValues
sWriter.WriteLine(setting.Name & "," & setting.PropertyValue.ToString())
Next
End Using
My.Settings.Save()
MessageBox.Show("Settings has been saved to the specified file", "Export", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Private Sub import_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles import.Click
Dim oDialog As New OpenFileDialog
oDialog.Filter = "Application Settings (*.AppSettings)|*AppSettings"
If oDialog.ShowDialog() = DialogResult.OK Then
Using sReader As New StreamReader(oDialog.FileName)
While sReader.Peek() > 0
Dim input = sReader.ReadLine()
' Split comma delimited data ( SettingName,SettingValue )
Dim dataSplit = input.Split(CChar(","))
' Setting Value
My.Settings(dataSplit(0)) = dataSplit(1)
End While
End Using
My.Settings.Save()
MessageBox.Show("Import of settings successfull", "Import", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Sub
Best Regards.
Jiachen Li
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
Hi @MarcMenzel-8677 ,
Have you tried the code above?
It can export the application's My.Settings to the .AppSettings file or import the settings from the .AppSettings file into My.Settings.
6 people are following this question.