I have a form with a textbox and I want that textbox to read from text file ,manipulate information in text file and write it to another text file. read each line and when see -- into line break and continue next line until to file end.this code have problem can you help me???

        private void button1_Click(object sender, EventArgs e)
        {

                textBox1.Text = openFileDialog1.FileName.ToString();

                string[] fileA = System.IO.File.ReadAllLines(@"textBox1.Text"); error it this line why???

            string[] fileB={};
            int count=0;

            foreach (string line in fileA)
            {

                string str = line;
                for (int i = 0; i < str.Length; i++)
                {
                    if (str[i] == '-')
                    {
                        if (str[i + 1] == '-')
                            break;
                    }
                    else
                    {

                        continue;
                    }

                    count++;

                }

                for (int j = 0; j < count; j++)
                {
                    fileB[j] = str[j].ToString(); 
                }


                System.IO.StreamWriter file =
                                              new System.IO.StreamWriter("c:\result.txt", true);



            }














    }

tring[] fileA = System.IO.File

What us the error you get on the line :
string[] fileA = System.IO.File.ReadAllLines(@"textBox1.Text"); ?

My bets are that you need to open the file in a stream ?

You can always also use :

System.IO.File.Copy ?

here you go

Html
  <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" 
            Text="Read from file" />
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" 
            Text="Modify and save " />
Code behind
  {
            //this calls the method to read from the file
            readFileintoTextbox();
        }

        private void readFileintoTextbox()
        {
            //reads text into textbox
            using (StreamReader reader = new StreamReader(@"C:\Dropbox\test\mystuff.txt"))
            {
                string contentOfFile = reader.ReadToEnd();
                TextBox1.Text = contentOfFile;


            }
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            //writes the contents of the textbox to a new file
            StreamWriter sw = File.CreateText(@"C:\Dropbox\test\mynewstuff.txt");
             sw.WriteLine(TextBox1.Text);
              sw.Close();
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.