Не сохраняется отсортированный файл(может быть и не сортируется)

[FORM1]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;

namespace sosa
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        public void button2_Click(object sender, EventArgs e)
        {

            string path = null;
            var dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                path = dialog.FileName;
            }
            textBox4.Text = path;
            MessageBox.Show(path);

        }

        public void button1_Click(object sender, EventArgs e)
        {
            //string FalderPath = null;
            //FolderBrowserDialog fld = new FolderBrowserDialog();
            //if (fld.ShowDialog() == DialogResult.OK)
            //{
            //    FalderPath = fld.SelectedPath;
            //}
            //textBox3.Text = FalderPath;
            //MessageBox.Show(FalderPath);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            Hide();
            form2.Show();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            string path = textBox4.Text;
            string llarrayOfMail = System.IO.File.ReadAllText(path);
            string separator = null;
            
            if (textBox1.Text == ", (comma)")
            {
                separator = ",";
            }
            else if(textBox1.Text == "; (semicolon)")
            {
                separator = ";";
            }
            else if(textBox1.Text == ": (colon)")
            {
                separator = ":";
            }
            else if(textBox1.Text == "space")
            {
                separator = " ";
            }
            else if (textBox1.Text == "enter")
            {
                separator = "\n";
            }
            else
            {
                separator = textBox1.Text;
            }

            char sep = Convert.ToChar(separator);
            string[] arrayOfMail = llarrayOfMail.Split(sep);
            string separator2 = textBox3.Text;
            
                foreach(var el in arrayOfMail)
                {
                    File.WriteAllText(path, el + separator2);
                }
        }

        public void label4_Click(object sender, EventArgs e)
        {

        }

        public void textBox1_TextChanged(object sender, EventArgs e)
        {

            string txt = textBox1.Text;
        }

        public void textBox2_TextChanged(object sender, EventArgs e)
        {
            string txt1 = textBox2.Text;
        }

        public void textBox3_TextChanged(object sender, EventArgs e)
        {
            string txt2 = textBox3.Text;
        }

        public void textBox4_TextChanged(object sender, EventArgs e)
        {

        }
    }
}

[FORM2]

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sosa
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }

        public void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            
            string textComboBox1 = comboBox1.Text;
            MessageBox.Show(textComboBox1);

        }

        public void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            Form1 form1 = new Form1();
            form1.textBox2.Text = comboBox2.Text;
            string textComboBox2 = comboBox2.Text;
            MessageBox.Show(textComboBox2);
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Form2 form2 = new Form2();
            Form1 form1 = new Form1();
            if (comboBox1.Text == "" || comboBox2.Text == "")
            {
                
                MessageBox.Show("choose correct separators");
            }
            else
            {
                form1.textBox1.Text = comboBox1.Text;
                form1.textBox2.Text = comboBox2.Text;
                
                MessageBox.Show("Parametrs set successfully");
                Hide();
                form1.Show();
            }

        }
    }
}


вариации разделителей

вот ошибка


Ответы (0 шт):