加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

C#是打开文件对话框中所选文件数量的限制

发布时间:2020-12-16 01:55:04 所属栏目:百科 来源:网络整理
导读:我有一个C# windows窗体应用程序,我从开放文件浏览器将 XML文件和CGM图形文件加载到我的应用程序中.我似乎能够一次选择几百个并且它没有故障,但是更多并弹出一个对话框告诉我它找不到这样的文件,但只提供了一半的文件名.我假设这是由于在一次打开文件对话框
我有一个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();  
    }  
}

解决方法

根据此 article,当您使用OpenFileDialog控件选择超过200个文件时,您将收到“选择了太多文件”错误消息.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读