gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 14:12:39 31 4
gpt4 key购买 nike

我有一个 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 个文件时,您将收到“选择的文件过多”错误消息。

关于C# 是否有打开文件对话框中所选文件数量的限制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16853210/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com