Error while moving directory

0

I have folderBrowserDialog that when we select the folder it would move it to a certain directory.

I'm having the following error:

  

Unable to create a file when this file already exists.

but the folder does not exist.

The code is as follows

    private void BtnUpload_Click(object sender, EventArgs e)
    {
        string domain2 = Domain + folderBrowserDialog1.SelectedPath;
        DialogResult result = folderBrowserDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            if (Directory.Exists(Domain))
            {
                Directory.Move(folderBrowserDialog1.SelectedPath, domain2);
            }
            else
            {
                Directory.CreateDirectory(Domain + "\projects");

            }
        }
        else
        {

        }
    }

Update

forget to say the following Domain is the following string

string Domain = AppDomain.CurrentDomain.BaseDirectory + "projects";

I made this small change.

    private void BtnUpload_Click(object sender, EventArgs e)
    {
        string domain2 = Domain + folderBrowserDialog1.SelectedPath;
        DialogResult result = folderBrowserDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            if (Directory.Exists(Domain))
            {
                try
                {
                    Directory.Move(folderBrowserDialog1.SelectedPath, domain2);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Faild to move the file maybe it already exist");
                }
            }
            else
            {
                Directory.CreateDirectory(Domain + "\projects");

            }
        }
        else
        {

        }
    }

continues with the same problem

    
asked by anonymous 23.08.2016 / 14:22

1 answer

0

I have solved the problem. I was trying to move the folder to
Domain + folderBrowserDialog1.SelectedPath;
or what I was trying to do was this
C: \ Location of the file moves to C: \ DirectoryC: \ The location of the file again.
This is the code

    private void BtnUpload_Click(object sender, EventArgs e)
    {
        string domain2 = Domain + "\Edit";
        DialogResult result = folderBrowserDialog1.ShowDialog();
        if (result == DialogResult.OK)
        {
            if (Directory.Exists(Domain))
            {
                try
                {
                    Directory.Move(folderBrowserDialog1.SelectedPath, domain2);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Faild to move the file maybe it already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                Directory.CreateDirectory(Domain);
                try
                {
                    Directory.Move(folderBrowserDialog1.SelectedPath, domain2);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Faild to move the file maybe it already exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
        else
        {

        }
    }
    
23.08.2016 / 15:24