Jump to content

read data from notepad

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
royvb

royvb

    Newbie

  • Members
  • Pip
  • 5 posts
I need to write the programming which to read the data file, start from the second line.

here, i provide u my code.

List<string> fi = new List<string>();
using (StreamReader sr = new StreamReader("c:\\PODB.txt"))
{
string line = null;
while ((line = sr.ReadLine()) != null)
{

fi.Add(line); //add to list
Console.WriteLine(line); //write to console
}

}

what i have to insert into my code..need help..ThanK you

#2
CommittedC0der

CommittedC0der

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,565 posts
umm...... your trying to read the second line of a .txt file? If so this might help:
  openFileDialog1.FileName = "";
                openFileDialog1.Title = "Open A Business Document.";

                openFileDialog1.Filter = "Business|*.bus";
                DialogResult result = openFileDialog1.ShowDialog(); // Show the dialog.
                if (result == DialogResult.OK) // Test result.
                {
                    int i = 0;
                    string file = openFileDialog1.FileName;
                    try
                    {
                        decimal[] Restore;
                        Restore = new decimal[22];


                        string line;

                        // Read the file and display it line by line.
                        using (StreamReader doc = new StreamReader(openFileDialog1.FileName))
                        {
                            while ((line = doc.ReadLine()) != null)
                            {
                                Restore[i] = Convert.ToDecimal(line);
                                i++;
                            }
                            #region Change Values
                            //Wokers cost
                            Workers.Value = Restore[0];
                            HourPayment.Value = Restore[1];
                            HourPerDay.Value = Restore[2];
                            DaysPerWeek.Value = Restore[3];
                       
                        }


                    }
                    catch
                    {
                        MessageBox.Show("An error has occurred");
                    }
That basically opens a .txt file into an array which you can take the value's from, for what you need.

EDIT: You will need to make it a string array not decimal. ;)
A man can be defined by what he does when no one is looking.
Science is only an educated theory, which we cannot disprove.