0
I have a folderBrowserDialog
that when we selected the folder it would move it to a particular directory.
I’m making the following mistake:
Cannot create a file when that 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 seguine string
string Domain = AppDomain.CurrentDomain.BaseDirectory + "projects";
I made this little 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
I have had similar problem with an application in another language (I believe it is a Windows problem, if it is the same situation). Please check if this folder was not created with another user and is not only visible to the current user, which would prevent a new one from being created with the same name, but at the same time via code identifies it as if the folder did not exist. I know - it’s bizarre.
– Bruno Bermann
This difference of folders between users I noticed happens by running the application in Administrator mode and creating a folder that the non-administrative user cannot view.
– Bruno Bermann