我有一个C#
windows窗体应用程序,我从开放文件浏览器将
XML文件和CGM图形文件加载到我的应用程序中.我似乎能够一次选择几百个并且它没有故障,但是更多并弹出一个对话框告诉我它找不到这样的文件,但只提供了一半的文件名.我假设这是由于在一次打开文件对话框中可以选择/处理的文件数量的限制.
有没有人知道这个数字是什么,如果我有超过这个限制一次选择,有没有办法绕过它?
我实际上将文件’导入’到我的应用程序中,使用foreach循环将所选文件移动到另一个文件夹,然后应用程序写入XML文件,其中包含导入文件的所有文件名(以及其他数据)在文件上).
以下是整个“导入”方法
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(); } }
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。