0 Replies - 263 Views - Last Post: 31 January 2018 - 04:23 PM Rate Topic: -----

#1 darthbreezy   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 31-January 18

Can you have multiple App.Config files in 1 program?

Posted 31 January 2018 - 04:23 PM

Hey guys,
I'm working on a project for work to handle server automation, at the moment I'm having to create app.config files that handle our server information. I need to be able to have 1 app config file that creates a .txt file called Macros.txt and another to create a .CONFIG file in a different location. Here is the code I have but when the second half runs app1.config, the .CONFIG file created has the same ConfigurationSettings as the 1st app.config file. How can I do both?

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Const DestinationDirectory As String = "C:\Program Files\F2K"
        Const SecondaryDirectory As String = "C:\Program Files\F2K\2ndFolderLocation"
        Try
            Dim appSettings As System.Collections.Specialized.NameValueCollection = System.Configuration.ConfigurationManager.AppSettings
            Dim appFile As System.IO.StreamWriter
            System.IO.Directory.CreateDirectory(DestinationDirectory)
            appFile = My.Computer.FileSystem.OpenTextFileWriter("C:\Program Files\F2K\Macros.txt", False)
            If appSettings.Count = 0 Then
                TextBox1.Text = "AppSettings is empty"
            Else
                For Each key As String In appSettings.AllKeys
                    appFile.WriteLine("<{0}>" & vbTab & "{1}", key, appSettings(key))
                Next
            End If
            appFile.Close()
        Catch ex As System.Configuration.ConfigurationerrorsException
            MessageBox.Show("Error reading app settings")
        End Try

THIS BOTTOM HALF OF THE CODE IS WHERE I'M HAVING PROBLEMS

        Try
            Dim appSettings As System.Collections.Specialized.NameValueCollection = System.Configuration.ConfigurationManager.AppSettings
            Dim appFile As System.IO.StreamWriter
            System.IO.Directory.CreateDirectory(SecondaryDirectory)
            appFile = My.Computer.FileSystem.OpenTextFileWriter("C:\Program Files\F2K\2ndFolderLocation\app.config", False)
            If appSettings.Count = 0 Then
                TextBox1.Text = "AppSettings is empty"
            Else
                For Each key As String In appSettings.AllKeys
                    appFile.WriteLine("<{0}>" & vbTab & "{1}", key, appSettings(key))
                Next
            End If
            appFile.Close()
        Catch ex As System.Configuration.ConfigurationerrorsException
            MessageBox.Show("Error reading app settings")
        End Try


Is This A Good Question/Topic? 0
  • +

Page 1 of 1