Need file read in from form load

Posted by Luke on Stack Overflow See other posts from Stack Overflow or by Luke
Published on 2010-04-19T15:55:31Z Indexed on 2010/04/19 16:03 UTC
Read the original article Hit count: 274

Filed under:

I am using a listview, and trying to populate using a file. I need the file to be read in as soon as the form starts.

private void mainForm_Load(object sender, EventArgs e)
    {
        //get file read in
        if (File.Exists("../../MealDeliveries.txt"))
        {
            StreamReader sr = new StreamReader("../../MealDeliveries.txt");
            //first line is delivery name
            string strDeliveryName = sr.ReadLine();
            do
            {
                //other lines
                Delivery d = new Delivery(strDeliveryName, sr.ReadLine(), sr.ReadLine(), sr.ReadLine(), sr.ReadLine(), sr.ReadLine(), sr.ReadLine());
                mainForm.myDeliveries.Add(d);
                //check for further values
                strDeliveryName = sr.ReadLine();
                //stop if no more values
            } while (strDeliveryName != null);
            displayDeliveries();
        }
    }

Should this work?

© Stack Overflow or respective owner

Related posts about c#