I have a problem with a program I am creating.....there are two areas where im getting a "object not set to an instance of an object" but I check to make sure the object is created before I try to do anything with it....I check to see if a file exists before I try to write to it or read from it.... see code below....
this is where I try to save a text file....
this is where I try to read from the text file in the form load event.....
not sure why this doesnt work...well..it works on the machine where I have Visual Studio installed..but I also have another machine that I test with....this machine doesnt have any files needed to run the application..so I create a setup program ...then send it to the test machine....if I comment out the streamreader code ...I dont get any errors..........?
thank you for any help....
-InkedGFX
this is where I try to save a text file....
if (File.Exists(Application.StartupPath + "\\HistData\\history.txt")) { writer = new StreamWriter(Application.StartupPath + "\\HistData\\history.txt", true); foreach (string item in history) { try { writer.WriteLine(item); } catch (Exception ex) { MessageBox.Show("Error Saving Data " + ex.Message, "Write ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } writer.Close(); Environment.Exit(0); } else { Environment.Exit(0); }
this is where I try to read from the text file in the form load event.....
string histText = Application.StartupPath + "\\HistData\\history.txt"; FileInfo historyTXT = new FileInfo(Application.StartupPath + "\\HistData\\history.txt"); if (!File.Exists(histText)) { File.Create(Application.StartupPath + "\\HistData\\history.txt"); // MessageBox.Show("No File!"); } else { reader = new StreamReader(Application.StartupPath + "\\HistData\\history.txt"); string line; ; try { while ((line = reader.ReadLine()) != null) { if (!compare.Contains(line)) { compare.Add(line); this.toolStripComboBox1.Items.Add(line); } // MessageBox.Show(line.ToString()); } } catch (Exception ex) { MessageBox.Show("||||| ERROR |||||\r\n" + ex.Message, "ERROR READING HISTORY", MessageBoxButtons.OK, MessageBoxIcon.Error); } } reader.Close();
not sure why this doesnt work...well..it works on the machine where I have Visual Studio installed..but I also have another machine that I test with....this machine doesnt have any files needed to run the application..so I create a setup program ...then send it to the test machine....if I comment out the streamreader code ...I dont get any errors..........?
thank you for any help....
-InkedGFX