ダウンロードフォルダからディレクトリ内の特定のサブフォルダにファイルを移動するソフトウェアを作成しています。サブフォルダは、コンボボックスによってユーザーが選択します。私はこのエラーを繰り返し発生します:System.IO.IOException: Cannot create a file when that file already exists.
また、これらのエラーは私のプログラムをインストールする人々のコンピュータで発生します...例外など。どうすればオフにできますか。また、なぜこのエラーが発生するのですか?これが私のコードです:
string pathUser4 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
string pathDownload4 = (pathUser4 + @"\Downloads\");
string sourceFile = pathDownload4 + listBox1.Text;
string pathdoc5 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string pathDownload5 = (pathdoc5 + @"\iracing\setups\");
string destinationFile = pathDownload5 + comboBox1.Text;
File.Move(sourceFile, destinationFile);
if (comboBox1.Text == "Select File Destination")
{
MessageBox.Show("Please Select A Destination Folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}