System.IO.File.WriteAllText opens after writing?

konkor

Member
Joined
Jul 27, 2011
Messages
7
Programming Experience
1-3
Basically I am saving text to 2 seperate ini files, also saving the checkbox.checked value so my form can skip the login and auto start. My only problem is when a user saves the information to the INI files after writing them they automatically open up the INI files for display. When the form loads it automatically fills in the fields and if the checkbox is active it checks all the correct details then starts, only problem is it loads the checkbox1.checked ini file then starts the main menu. How can I skip this? and make it not show the ini files everytime they are called upon?

VB.NET:
Dim aINIpath As String
        aINIpath = "\User.ini"

If File.Exists(aINIpath) = False Then
            File.Create(aINIpath)
        End If

System.IO.File.WriteAllText(Application.StartupPath & "\User.ini", TextBox1.Text)
        System.Diagnostics.Process.Start(Application.StartupPath & "\User.ini")[/SIZE][/FONT]
 
The INI files are not "automatically opened". You are opening them explicitly. That's exactly what that call to Process.Start does so, if that's not what you want, why is it there?

Also, your checking for the file and creating it is pointless. WriteAllText creates the file if it doesn't exist.
 
I have never worked with the write to file functions before, so this is a first for me. Instead of listing the things I have done wrong, can you help me to solve them?
I took out the things you mentioned, it still works but still opens the file afterwards:

VB.NET:
Dim wINIpath As String
        wINIpath = "\Login.ini"


        System.IO.File.WriteAllText(Application.StartupPath & "\Login.ini", CheckBox1.Checked)

Sorry if this is really easy to do, but I have never really used any of these functions before for reading/writing to files.

VB.NET:
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.FileNotFoundException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
A first chance exception of type 'System.InvalidCastException' occurred in Microsoft.VisualBasic.dll

I am now getting these errors, all I have done is remove the "if its not there create it" and the "process.start" it was working but now it just gives me that error even if i put the stuff back to the way it was.

EDIT: I have fixed it all, the only problem I have now is an exception error on start up that cannot locate \login.ini?
 
Last edited:
Back
Top