How do I iterate My.Settings?

Posted on 2008-11-09
Last Modified: 2012-05-05
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). there a better way of doing this?
Question by:DavidRothan
    LVL 83

    Expert Comment

    I think you could use the app.config file. You can replicate the app.config file and customise it for each user.
    LVL 96

    Accepted Solution

    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


    Author Closing Comment

    Thanks very much!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Article by: jpaulino
    XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String ( Literal, only instead of starting and ending with w…
    Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now