Hi all,
I am new here and to programming and i am currently trying to build an interactive form for my works. I have my form which at the moment saves text from textbox1 to a .txt file and also i have succeeded in being able to read this back into a textbox of my choice.
My probelm is that i want "line 1" from the text file to go to one textbox and "line 2" to go to another. I have used StreamWriter and StreamReader and i have managed to read back "line 1" but i cannot figure out how to tell it to read "line 2".
My code at present is as follows:
using System;
using System.IO;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
//Creating a new stream-writer and opening the file.
System.IO.StreamWriter StreamWriter1 = new System.IO.StreamWriter(@"C:\Test.txt");
//Writing text to the file.
StreamWriter1.Write(textBox1.Text);
//Close the file.
StreamWriter1.Close();
}
private void button2_Click(object sender, EventArgs e)
{
//Creating a new stream-reader and opening the file.
System.IO.StreamReader StreamReader1 = new System.IO.StreamReader(@"C:\Test.txt");
//Reading Line from file
String text = StreamReader1.ReadLine();
//Writing the read line to textBox
textBox3.Text = text;
//Close the file
StreamReader1.Close();
}
}
}
I have searched through the forums already, which were really helpfull but I'm stuck here.
Hope i have provided enough information.
Thanks in advance
Michael