Modify .INI file line

Alex_W

Member
Joined
Jan 5, 2009
Messages
22
Programming Experience
Beginner
Hi guys,

I'm trying to read an entry in an ini file; if it reads "ShowInvoiceRequiredMsg=NO" then my program is going to give the option to change that line to "ShowInvoiceRequiredMsg=YES". My code below reads the file and picks up if the option is set to 'NO' but I can't seem to modify that line to change it to 'YES'....... (in red is where I'm trying to modify this text)

VB.NET:
 Dim file As System.IO.File
        Dim reader As System.IO.StreamReader
        Dim line As String
        reader = file.OpenText("c:\file.ini")
        
        'loop through each line
        While reader.Peek <> -1
            line = reader.ReadLine()

            'check for specific word
            If line.Contains("ShowInvoiceRequiredMsg=NO") Then
                If MessageBox.Show("The Invoice Required Dialog is disabled, do you want to re-enable it?", _
"Invoice Required Dialog", MessageBoxButtons.YesNo, MessageBoxIcon.Information,_
 MessageBoxDefaultButton.Button1) = Windows.Forms.DialogResult.Yes Then
                    [COLOR="Red"]line.ToString.Equals("ShowInvoiceRequiredMsg=YES")[/COLOR]
                Else
                    Exit Sub
                End If
            End If
        End While
        reader.Close()
Any help appreciated.
 
Last edited:
Just to let everyone know I managed to use the following code to do this:

VB.NET:
Dim fileContents As String = System.IO.File.ReadAllText(LANLocation & "\file.ini")

                fileContents = fileContents.Replace("ShowInvoiceRequiredMsg=NO", "ShowInvoiceRequiredMsg=YES")

                System.IO.File.WriteAllText(LANLocation & "\file.ini", fileContents)

LANLocation being set to retrieve a registry value to where the .ini file is installed.

Cheers,
Alex_W
 
Back
Top