检查 zip 文件的内容然后打开并阅读它并使用 c# WF 将内容列表到组合框中

check content of zip file then Open and Read it and list content into comboBox using c# WF

如果有 csv 文件,我想检查 zip 文件的内容。如果是这样我想把这个内容列成一个comboBox。我尝试的工作正常,但没有完成检查。

var = comboBox1.SelectedItem.ToString();
            fullpath = fbd.SelectedPath + "\"+ var;

            comboBox2.Items.Clear();
            if (File.Exists(fullpath)) 
            {
                ZipArchive zip = ZipFile.OpenRead(fullpath);
                foreach (ZipArchiveEntry entry in zip.Entries)
                {
                    comboBox2.Items.Add(entry.FullName); // fill comboBox2 with *.csv files from selected zip file
                }
                zip.Dispose();
            }
            else
            {
                MessageBox.Show("no csv files present");
            }

在将文件添加到组合框之前,您需要添加检查文件是否真的是 CSV。

使用此检查:

if (entry.Name.EndsWith("csv")
    comboBox2.Items.Add(entry.FullName);