• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 733
  • Last Modified:

How do I iterate My.Settings?

I'm developing an app using VB 2008.

I'd like to save each of 'my.settings' to a text file, so that a users 'my.settings' can be exported to another users machine.

I thought it would be easy to iterate each setting, write the current setting name and value to a simple text file and then read 'em back in a similar fashion.

I can't see a way. I don't need to know about the streamwriter / reading / writing text files, just how to iterate my.settings (if that is possible).

Or....is there a better way of doing this?
1 Solution
I think you could use the app.config file. You can replicate the app.config file and customise it for each user.
Bob LearnedCommented:
Maybe this might help:

Imports System.Configuration
Public Class ConnectionStringHelper
    Public Shared Sub ChangeConnectionString(ByVal key As String, ByVal originalServer As String, ByVal newServer As String)
        For Each [property] As SettingsProperty In My.MySettings.Default.Properties
            Dim name As String = [property].Name
            If name = key Then
                Dim connectionString As String = My.MySettings.Default.Item(name)
                My.MySettings.Default.Item(name) = connectionString.Replace(originalServer, newServer)
                Exit For
            End If
    End Sub
End Class

Open in new window

DavidRothanAuthor Commented:
Thanks very much!

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now