Hi. I am working on my Final for my Intro to C# class so yes I am new and my code is pretty unprofessional probably. We are required to use a array or a class to read addresses from a text file and display them in the GUI. We should be able to add new addresses and delete address and sort the arraylist by Name. Ok Everything works except...the reading and writing to the text file and the sorting. I tried the following to write to the text file which I have in the bin/debug folder of the program. Also I am using Visual Studio 2003 .Net Framework1.1 just in case that helps. ok here is the code I don't get any errors but the file is still blank when I open it.
private void menuSave_Click(object sender, System.EventArgs e)
{
// if the file exists
if (File.Exists("AddressList.txt"))
{
try
{
// creates a new StreamWriter
StreamWriter output = new StreamWriter(Application.StartupPath + "\\AddressList.txt");
// writes each friend to the text file
foreach(Friend fr in friendArray)
{
output.Write(fr.friendName, fr.friendStreet, fr.friendCity, fr.friendState, fr.friendZip);
}
//closes the file
output.Close();
}
catch(System.IO.IOException exc)
{
MessageBox.Show(exc.Message);
}
}
else
{
MessageBox.Show("File Not Found");
}
}
I also tried:
output.Write(" {0}, {1}, {2}, {3}, {4}",fr.friendName, fr.friendStreet, fr.friendCity, fr.friendState, fr.friendZip);
Didnt work either. :(