Keep the text in textboxes saved <p>I have these textboxes where the user enters data and then presses a button to process the data. Now the data entered by the user is alot and to give the user some slack I want to make it possible whenever you press the button, the application saves the data, so when you close the application and start it back up again the textboxes are filled with the last entered data.</p> <p>I was thinking about using a .txt file to save the data. Only I have found some difficulties with this. One of the problems is that I keep getting a messagebox from the microsoft .NET Framework everytime I try to run my application. The messagebox says the Index was outside the bounds of the array. Even though I think my code doesn't exceed the bounds of my array.</p> <p>And here is the code that I use:</p> <p>First I declared an array and filled it with variables that contain the content of the textboxes:</p> <pre><code>string[]settings = new string[5]; settings[0] = openKey; settings[1] = secretKey; settings[2] = statusRequestPath; settings[3] = statusRequestAPI; settings[4] = setSeconds.ToString(); </code></pre> <p>Then I use the following code to write the data to a text file.</p> <pre><code>using (StreamWriter writeFile = new StreamWriter(@"C:\Audio Silence Detector\AudioSilenceDetector.txt")) { foreach (string line in settings) { writeFile.WriteLine(line); } } </code></pre> <p>And to put the text of the .txt file back in the application I have put this in the formload:</p> <pre><code>string[] lines = System.IO.File.ReadAllLines(@"C:\Audio Silence Detector\AudioSilenceDetector.txt"); tbOpenKey.Text = lines[0]; tbSecretKey.Text = lines[1]; tbStatusRequestPath.Text = lines[2]; tbStatusRequestAPI.Text = lines[3]; tbSeconds.Text = lines[4]; </code></pre> <p>I changed my code to this and it seems to have fixed the issue I was having:</p> <pre><code> if (lines.LongLength == 5) { tbOpenKey.Text = lines[0]; tbSecretKey.Text = lines[1]; tbStatusRequestPath.Text = lines[2]; tbStatusRequestAPI.Text = lines[3]; tbSeconds.Text = lines[4]; } </code></pre>