• 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?
0
DavidRothan
Asked:
DavidRothan
1 Solution
 
CodeCruiserCommented:
I think you could use the app.config file. You can replicate the app.config file and customise it for each user.
0
 
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)
                My.MySettings.Default.Save()
 
                Exit For
            End If
        Next
 
    End Sub
 
End Class

Open in new window

0
 
DavidRothanAuthor Commented:
PERFECT!
Thanks very much!
0

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