Best way to save small amount of data

I have a small window where I ask the user set a few options, what's the best way and
the most common way to save the data so the application is aware of it the next time it starts.
How to save and load data is my question, really :) Thanks.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Bob LearnedCommented:
The "Best way" involves a judgement call, and everybody has their opinions

1) Write an XML file
2) Write a simple text file
3) Save to registry (not the best in my opinion)

What kind of options are you talking about?

vpekulasAuthor Commented:
Let's say the XML, can you show me a sample write and read ? Thanks.
Mike TomlinsonMiddle School Assistant TeacherCommented:
Here is a simple example of saving the "start position" of a form via XML serialization:

Imports System.IO
Imports System.Xml.Serialization

Public Class Form1

    Private filename As String = "c:\someFile.xml"

    Public Class FormSettings
        Public FormLocation As Point
        Public FormSize As Size

        Public Sub New()
        End Sub

        Public Sub New(ByVal f As Form)
            Me.FormLocation = f.Location
            Me.FormSize = f.Size
        End Sub
    End Class

    Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If File.Exists(filename) Then
            Dim xml As XmlSerializer = New XmlSerializer(GetType(FormSettings))
            Dim reader As TextReader = New StreamReader(filename)
            Dim fs As FormSettings = CType(xml.Deserialize(reader), FormSettings)
            Me.Location = fs.FormLocation
            Me.Size = fs.FormSize
        End If
    End Sub

    Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        Dim xml As XmlSerializer = New XmlSerializer(GetType(FormSettings))
        Dim writer As TextWriter = New StreamWriter(filename)
        xml.Serialize(writer, New FormSettings(Me))
    End Sub

End Class
Bob LearnedCommented:
Here is another way:

Imports System.Xml

Public Class Settings

#Region "Properties"

  Private m_userName As String = ""
  Public Property UserName() As String
      Return m_userName
    End Get
    Set(ByVal Value As String)
      m_userName = Value
    End Set
  End Property  'UserName

  Private m_fontName As String = ""
  Public Property FontName() As String
      Return m_fontName
    End Get
    Set(ByVal Value As String)
      m_fontName = Value
    End Set
  End Property  'FontName

#End Region

#Region "Methods"

  Private m_document As New XmlDocument

  Public Sub Load(ByVal fileName As String)

    If IO.File.Exists(fileName) Then

      Me.UserName = GetNodeValue("UserName")
      Me.FontName = GetNodeValue("FontName")
    End If

  End Sub  'Load

  Private Function GetNodeValue(ByVal name As String) As String

    Dim node As XmlNode = m_document.SelectSingleNode("//" & name)

    If Not node Is Nothing Then
      Return node.InnerText
    End If

    Return ""

  End Function  'GetNodeValue

  Public Sub Save(ByVal fileName As String)

    m_document = New XmlDocument

    Dim settings As XmlElement = Me.AddElement(m_document, "Settings", "")
    Dim userName As XmlElement = Me.AddElement(settings, "UserName", Me.UserName)
    Dim fontName As XmlElement = Me.AddElement(settings, "FontName", Me.FontName)


  End Sub  'Save

  Private Function AddElement(ByVal owner As XmlNode, ByVal name As String, ByVal value As String) As XmlElement

    Dim element As XmlElement = m_document.CreateElement(name)

    If value.Length > 0 Then
      element.InnerText = value
    End If


    Return element

  End Function  'AddElement

#End Region

End Class
Bob LearnedCommented:

  Dim settings As New Settings
  settings.UserName = "Bob"
  settings.FontName = "Tahoma"

  Dim test As New Settings
  MessageBox.Show("User:  " & test.UserName & ", Font:  " & test.FontName)


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.