Как показать количество перемещенных файлов и имя перемещенного файла в диалоговом окне

У меня есть функция перемещения, которая перемещает файлы из одной папки в другую папку. Мне интересно, как я могу показать общее количество файлов перемещенных и перемещенных имен файлов в диалоговом окне. или любая идея..!!!!

Здесь проблема в том, что как только я нажимаю Переместить все перемещающиеся файлы, если вообще есть какие-то дубликаты файлов, это показывает ошибку msg в моем виде сетки. Остальные файлы начинают двигаться. Так что мне нужен метод, как только все файлы перемещены.. мне нужно показать диалоговое окно с общим количеством перемещенных файлов и имен файлов, перемещенных в диалоговом окне... это возможно... или любая идея... Пожалуйста, опубликуйте это..

Я действительно ценю это..

Мои коды:

 private void button3_Click(object sender, EventArgs e)
{
    update = false;
    this.Enabled = false;
    backgroundWorker2.RunWorkerAsync();
    move();
    backgroundWorker2.CancelAsync();
    System.Threading.Thread.Sleep(500);
    this.Enabled = true;
    update = true;
}

public void move()
{
    update = false;
    string archieve_path = ini.ReadValue("Location", "Archive");
    string release_path = ini.ReadValue("Location", "Release");
    string draft_path = ini.ReadValue("Location", "Draft");
    for (int i = 0; i < dataGridView1.Rows.Count; i++)
    {
        if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString()) && String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
            (dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
        {
            string draftpath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
            string relasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
            string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
            string draftname = System.IO.Path.GetFileName(draftpath);
            if (relasepath != string.Empty && draftname.Equals(Path.GetFileName(relasepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            string newpath = System.IO.Path.Combine(release_path, draftname);
            System.IO.File.Move(draftpath, newpath);
            dataGridView1.Rows[i].Cells["Release Path"].Value = newpath;
            dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
            dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
        }
        if ((!String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString())
            && !String.IsNullOrEmpty(dataGridView1.Rows[i].Cells["Release Path"].Value.ToString())) &&
            (dataGridView1.Rows[i].Cells[0].Value != null && (bool)dataGridView1.Rows[i].Cells[0].Value))
        {
            string draftPath = dataGridView1.Rows[i].Cells["Draft Path"].Value.ToString();
            string releasepath = dataGridView1.Rows[i].Cells["Release Path"].Value.ToString();
            string archievepath = dataGridView1.Rows[i].Cells["Archive"].Value.ToString();
            string draftname = System.IO.Path.GetFileName(draftPath);
            string archievename = System.IO.Path.GetFileName(archievepath);
            string releasename = System.IO.Path.GetFileName(releasepath);
            if (archievepath != string.Empty && draftname.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            if (releasepath != string.Empty && draftname.Equals(Path.GetFileName(releasepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Release: " + draftname + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            if (archievepath != string.Empty && releasename.Equals(Path.GetFileName(archievepath), StringComparison.OrdinalIgnoreCase))
            {
                dataGridView1.Rows[i].Cells["Error"].Value = "Duplicate in Archive: " + releasename + "";
                dataGridView1.Rows[i].Cells["Error"].Style = new DataGridViewCellStyle { ForeColor = Color.Red };
                continue;
            }
            string fName1 = System.IO.Path.GetFileNameWithoutExtension(draftPath);
            string fName2 = System.IO.Path.GetFileNameWithoutExtension(releasepath);
            string fName3 = System.IO.Path.GetFileNameWithoutExtension(archievepath);
            var f1 = GetValue(fName1.ToCharArray()[fName1.Length - 2]) * 16 + GetValue(fName1.ToCharArray()[fName1.Length - 1]);
            var f2 = GetValue(fName2.ToCharArray()[fName2.Length - 2]) * 16 + GetValue(fName2.ToCharArray()[fName2.Length - 1]);
            // var f3 = GetValue(fName3.ToCharArray()[fName3.Length - 2]) * 16 + GetValue(fName3.ToCharArray()[fName3.Length - 1]);
            if (f1 > f2)//till here
            {
                //moves from realse to archieve
                string newpath = System.IO.Path.Combine(archieve_path, releasename); //draft name + archieve
                System.IO.File.Move(releasepath, newpath);
                dataGridView1.Rows[i].Cells["Release Path"].Value = string.Empty;
            }
            if (f1 < f2)
            {
                //moves draft to archieve
                string newpath = System.IO.Path.Combine(archieve_path, draftname);
                System.IO.File.Move(draftPath, newpath);
                dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
                return;
            }
            string newpath1 = System.IO.Path.Combine(release_path, draftname);
            System.IO.File.Move(draftPath, newpath1);
            dataGridView1.Rows[i].Cells["Release Path"].Value = newpath1;
            dataGridView1.Rows[i].Cells["Draft Path"].Value = string.Empty;
            dataGridView1.Rows[i].Cells[0].Value = false; //Checkbox
        }
    }
    update = true;
}

Добавлен код:

 StringBuilder sbBody = new StringBuilder();
        List<string> lstFiles = new List<string>();

foreach (string file in Directory.GetFiles(newpath, "*.txt"))
                {
                    // msg.Attachments.Add(new System.Net.Mail.Attachment(file));
                    lstFiles.Add(file);
                }

1 ответ

Я бы подумал, что это дурак, но, видимо, это не так. Во всяком случае, вот схема.

Добавить ProgressChanged событие в backgroundWorker2и запустить move() а также (что потребует переписывания функции, чтобы разделить весь код, который обновляет пользовательский интерфейс на наличие ошибок и тому подобное, в ProgressChanged делегатские звонки). В обработчике событий обновите пользовательский интерфейс с помощью недавно измененных данных счетчика и имени файла из параметров.

Другие вопросы по тегам