private void button_load_file_Click(object sender, EventArgs e) { comboBox_creditors.Enabled = false; Stream myStream = null; OpenFileDialog ofd = new OpenFileDialog(); ofd.Title = "Open Text File"; ofd.Filter = "TXT files|*.txt"; ofd.InitialDirectory = @"C:\"; if (ofd.ShowDialog() == DialogResult.OK) { try { if ((myStream = ofd.OpenFile()) != null) { if (!CheckReadyToLoadData()) { MessageBox.Show("Не указан тип адреса или шаблон письма.", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Warning); } string template = comboBox_template.SelectedItem.ToString(); AdressType adrtype = (AdressType)comboBox_adr.SelectedIndex; List<RecordToInsert> recList = new List<RecordToInsert>(); using (myStream) { var lines = File.ReadLines(ofd.FileName); foreach (var line in lines) { RecordToInsert rec = new RecordToInsert { DealId = line, TemplateId = template, AdrType = adrtype }; recList.Add(rec); } } LetterManager.AddPinFromFile(recList); } else { comboBox_creditors.Enabled = true; } } catch (Exception ex) { MessageBox.Show("Не удается прочитать файл. " + ex.Message); } } }