You can create the application setting for each user using IsolatedStorage. Here is the sample code to store and retrieve the application settings:
Public Class AppSettings
Private _configFileName As String
Private _configFileType As Config
Public Enum Config
SharedFile
PrivateFile
End Enum
Public Sub New(ByVal ConfigFileType As Config)
_configFileType = ConfigFileType
InitializeConfigFile()
End Sub
Private Sub InitializeConfigFile()
Dim sb As New Text.StringBuilder
Select Case _configFileType
Case Config.PrivateFile
sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData))
Case Config.SharedFile
sb.Append(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData))
End Select
sb.Append("\")
sb.Append(Application.ProductName)
If Not IO.Directory.Exists(sb.ToString) Then
IO.Directory.CreateDirectory(sb.ToString)
End If
sb.Append("\")
sb.Append(Application.ProductName)
sb.Append(".config")
_configFileName = sb.ToString
If Not IO.File.Exists(_configFileName) Then
Dim fn As New IO.StreamWriter(IO.File.Open(_configFileName, IO.FileMode.Create))
fn.WriteLine("")
fn.WriteLine("<configuration>")
fn.WriteLine(" <appsettings>")
fn.WriteLine(" <!-- User application and configured property settings go here.-->")
fn.WriteLine(" <!-- Example: <add key=""settingName"" value=""settingValue""/> -->")
fn.WriteLine(" </appsettings>")
fn.WriteLine("</configuration>")
fn.Close()
End If
End Sub
Public Function GetSetting(ByVal key As String) As String
Dim xd As New Xml.XmlDocument
xd.Load(_configFileName)
Dim Node As Xml.XmlNode = xd.DocumentElement.SelectSingleNode( _
"/configuration/appSettings/add[@key=""" & key & """]")
If Not Node Is Nothing Then
Return Node.Attributes.GetNamedItem("value").Value
Else
Return Nothing
End If
End Function
Public Sub SaveSetting(ByVal key As String, ByVal value As String)
Dim xd As New Xml.XmlDocument
xd.Load(_configFileName)
Dim Node As Xml.XmlElement = CType(xd.DocumentElement.SelectSingleNode( _
"/configuration/appSettings/add[@key=""" & _
key & """]"), Xml.XmlElement)
If Not Node Is Nothing Then
Node.Attributes.GetNamedItem("value").Value = value
Else
Node = xd.CreateElement("add")
Node.SetAttribute("key", key)
Node.SetAttribute("value", value)
Dim Root As Xml.XmlNode = xd.DocumentElement.SelectSingleNode("/configuration/appSettings")
If Not Root Is Nothing Then
Root.AppendChild(Node)
Else
Try
Root = xd.DocumentElement.SelectSingleNode("/configuration")
Root.AppendChild(xd.CreateElement("appSettings"))
Root = xd.DocumentElement.SelectSingleNode("/configuration/appSettings")
Root.AppendChild(Node)
Catch ex As Exception
Throw New Exception("Could not set value", ex)
End Try
End If
End If
xd.Save(_configFileName)
End Sub
End Class