c sharp text file application

Associate
Joined
10 Apr 2012
Posts
1
hi everyone, i have created a text file windows application which reads in 10 records, i was wondering how to read the records one by one into a textbox when a button is pressed, and also when the edit or save button is pressed, this will take the user to a 2nd form for saving and editing the text file which has been loaded, i have already created some strings. any help would be much appreciated

class Program
{

private struct person //creates new person structure//
{
public int list;
public string lastName; record
public string firstName;
public string middlename;
public DateTime dob; //datetime class is used for date of birth
public string gender;
public string toString()
 
Associate
Joined
26 Apr 2009
Posts
204
hi everyone, i have created a text file windows application which reads in 10 records, i was wondering how to read the records one by one into a textbox when a button is pressed, and also when the edit or save button is pressed, this will take the user to a 2nd form for saving and editing the text file which has been loaded, i have already created some strings. any help would be much appreciated

class Program
{

private struct person //creates new person structure//
{
public int list;
public string lastName; record
public string firstName;
public string middlename;
public DateTime dob; //datetime class is used for date of birth
public string gender;
public string toString()

PHP:
        try
        {
            // Create an instance of StreamReader to read from a file.
            // The using statement also closes the StreamReader.
            using (StreamReader sr = new StreamReader("TestFile.txt"))
            {
                String line;
                // Read and display lines from the file until the end of
                // the file is reached.
                while ((line = sr.ReadLine()) != null)
                {
                       textBox1.Text = textBox1.Text + "\n" + line;
                }
            }
        }
        catch (Exception e)
        {
            // Let the user know what went wrong.
            Console.WriteLine("The file could not be read:");
            Console.WriteLine(e.Message);
        }

You want to put that code into the button you want the event to be actioned from
 
Back
Top Bottom