I am trying to configure a export settings option in my program. I have everything completed except for the my.settings that are list collections. I converted them to a string prior to exporting them and when a user imports it, it needs to go back to a list collection to be added to the app.config. Here is my code:
Export Option
VB Code:
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click Dim M_Count As String = String.Join("*", My.Settings.M_Count) Dim M_IPs As String = String.Join("*", My.Settings.M_IPs) Dim M_Hostnames As String = String.Join("*", My.Settings.M_Hostnames) Dim M_Descriptions As String = String.Join("*", My.Settings.M_Descriptions) Dim M_Results As String = String.Join("*", My.Settings.M_Results) Dim M_Exclusions As String = String.Join("*", My.Settings.M_Exclusions) Dim SaveFile As New SaveFileDialog SaveFile.FileName = "" SaveFile.Filter = "Client Watch Settings (*.k22cw)|*.k22cw" SaveFile.Title = "Save" SaveFile.ShowDialog() Try File.WriteAllText(SaveFile.FileName, String.Join("|", New String() {My.Settings.S_Email, My.Settings.S_Password, My.Settings.S_Port, My.Settings.S_SendTo, My.Settings.S_Hostname, M_IPs, M_Hostnames, M_Descriptions, M_Results, M_Exclusions, My.Settings.S_PingEveryM, My.Settings.Stats_Count, My.Settings.M_FailedIPs, My.Settings.M_SentCount, My.Settings.S_Tolerence, My.Settings.Logs, My.Settings.Stats_RunTime, My.Settings.Stats_SentAlerts, My.Settings.Stats_YTDfail, My.Settings.Stats_YTDsuccess})) Catch ex As Exception MsgBox(ex.Message) End Try End Sub
Import Option *This is where I am having the issue of converting back to a list collection
vb Code:
Private Sub Button8_Click(sender As Object, e As EventArgs) Handles Button8.Click Dim OpenFile As New OpenFileDialog OpenFile.FileName = "" OpenFile.Filter = "Client Watch Settings (*.k22cw)|*.k22cw" OpenFile.Title = "Open" OpenFile.ShowDialog() Try Dim values() As String = File.ReadAllText(OpenFile.FileName).Split("|"c) My.Settings.S_Email = values(0) My.Settings.S_Password = values(1) My.Settings.S_Port = values(2) My.Settings.S_SendTo = values(3) My.Settings.S_Hostname = values(4) Dim M_IPs As String = String.Join(",", values(5).ToArray()) Dim M_Hostnames As String = values(6) Dim M_Descriptions As String = values(7) Dim M_Results As String = values(8) Dim M_Exclusions As String = values(9) My.Settings.S_PingEveryM = values(10) My.Settings.Stats_Count = values(11) My.Settings.M_FailedIPs = values(12) My.Settings.M_SentCount = values(13) My.Settings.S_Tolerence = values(14) My.Settings.Logs = values(15) My.Settings.Stats_RunTime = values(16) My.Settings.Stats_SentAlerts = values(17) My.Settings.Stats_YTDfail = values(18) My.Settings.Stats_YTDsuccess = values(19) Dim M_Ips2 As String() = M_IPs.Split("*") My.Settings.M_IPs = M_Ips2.ToList 'This is where the error is happening. I haven't added the other settings yet... Catch ex As Exception End Try End Sub
The goal is to export the app.config and be able to import it. I tried following this article: http://vbcity.com/forums/t/163200.aspx however, it became more of a mess than what it was worth and figured I could accomplish the same result... but with more leg work of course. So that's where converting a list collection to a string came into play because some of my settings are list collections. I followed the instructions here: https://www.dotnetperls.com/convert-list-string-vbnet and the options for converting it back throws me a message saying I cannot convert array to list collection.
Any help or criticism would be awesome.




Reply With Quote
