I've got a C# windows forms application where I load XML files and CGM graphics files into my application from an Open File browser. I seem to be able to select a couple of hundred at a time and it works without fault, but any more and a dialog box pops up telling me it can't find file such and such, but only gives half the file name. I'm assuming this is due to a limit on the amount of files that can be selected / processed in one go through the open file dialog.
Does anybody know what that number is, and is there a way around it if i have more than that limit to select at once?
I'm effectively 'importing' the files into my application, whereby using a foreach loop the selected files get moved to another folder, and the application writes to an XML file with all the file names of the files imported (as well as other data on the files).
Below is the entire 'import' method
private void addFilesToCSDBToolStripMenuItem_Click(object sender, EventArgs e)
{
int DMsimported = 0;
int graphicsImported = 0;
if (projectName == "")
{
MessageBox.Show("Please open a project first", "DAWS");
return;
}
DialogResult result = openFileDialog1.ShowDialog();
if (result == DialogResult.OK)
{
MessageBox.Show("This process may take several minutes depending on the number of imports", "DAWS");
Application.UseWaitCursor = true;
foreach (string file in openFileDialog1.FileNames)
{
string fileName = Path.GetFileNameWithoutExtension(file); //Gets just the name from the file path
string ext = Path.GetExtension(file.ToLower());
if (ext != ".CGM" && ext != ".cgm")
{
bool exists = xmlFileWriter.checkIfFIleExists(fileName + ext);
if (exists != true)
{
xmlFileWriter.writeDatatoXML(file);
File.Move(file, CSDBpath + projectName + "\\CheckedIN\\" + fileName + ext);
DMsimported = DMsimported + 1;
}
else
{
MessageBox.Show(fileName + " already exists in the CSDB. This file will be skipped.", "DAWS");
}
}
else
{
if (File.Exists(CSDBpath + projectName + "\\Graphics\\" + fileName + ext))
{
if (Properties.Settings.Default.OverwriteGraphics == true)
{
File.SetAttributes(CSDBpath + projectName + "\\Graphics\\" + fileName + ext, FileAttributes.Normal); // need this line in order to set the file attributes. Exception thrown otherwise when system tries to overwrite the file.
File.Delete(CSDBpath + projectName + "\\Graphics\\" + fileName + ext);
File.Copy(file, CSDBpath + projectName + "\\Graphics\\" + fileName + ext); //need to give the option as to whether to delete the existing file or skipp.
}
else
{
MessageBox.Show(fileName + " already exists in the CSDB. This file will be skipped. To enable overwriting tick the checkbox in Preferences", "DAWS");
}
}
else
{
File.Copy(file, CSDBpath + projectName + "\\Graphics\\" + fileName + ext);
}
graphicsImported = graphicsImported + 1;
}
}
Application.UseWaitCursor = false;
buildAllListViews();
copyCGMfilesToDirectories();
if (DMsimported > 0)
{
MessageBox.Show(DMsimported.ToString() + " DM files successfully imported into the CSDB", "DAWS");
}
if (graphicsImported > 0)
{
MessageBox.Show(graphicsImported.ToString() + " graphic files successfully imported into the CSDB", "DAWS");
}
if (graphicsImported == 0 && DMsimported == 0)
{
MessageBox.Show("No files imported", "DAWS");
}
updateMainFilesList();
}
}