private void openFileDialog1_FileOk(object sender, CancelEventArgs e) { var fileInfo = new System.IO.FileInfo(openFileDialog1.FileName); if (fileInfo.Length > 20971520) { MessageBox.Show("Файл больше 20 МБ и не может быть загружен"); return; } DataRow NewRow = AttachmentDocumentsDataTable.NewRow(); NewRow["FileName"] = openFileDialog1.SafeFileName; NewRow["Path"] = openFileDialog1.FileName; AttachmentDocumentsDataTable.Rows.Add(NewRow); if (AttachmentDocumentsDataTable.Rows.Count != 0) { if (ClientContractDataGrid.SelectedRows.Count == 1) { ClientPayments.AttachDocuments(AttachmentDocumentsDataTable, ClientContractDataGrid.SelectedRows[0].Cells["ContractId"].Value.ToString()); } } }