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