Hey Guys,
I'm Learning a bit more about things you can do with OpenFileDialog. One of the things was to see if I could move a file to specfic destination depending on the filename. That works fine However come to a halt when trying to do the same thing with multipleSelect.
here's the code:
private void importToolStripMenuItem_Click(object sender, System.EventArgs e)
{
openFileDialog1.Multiselect = true;
string filename = null;
string dir = @"C:\folder1";
string dir2 = @"C:\folder2";
string dir3 = @"C:\folder3";
if (openFileDialog1.ShowDialog() == DialogResult.OK && openFileDialog1.FileName != "")
{
filename = openFileDialog1.SafeFileName;
;
foreach (string file in openFileDialog1.FileNames)
{
try
{
if (filename.ToUpper().Contains("fish".ToUpper()))
{
File.Move(openFileDialog1.FileName.ToString(), dir + filename);
}
else if (filename.ToUpper().Contains("hydra".ToUpper()))
{
File.Move(openFileDialog1.FileName.ToString(), dir2 + filename);
}
else
{
File.Move(openFileDialog1.FileName.ToString(), dir3 + filename);
}
}
catch (Exception ex) { MessageBox.Show(ex.Message); }
}
}
}
I can select multiple files, however it tells me that it couldnt find the first file despite it has been moved already and it won't continue with the rest of the files.
Cheers