C# 使用ZipFile压缩列表框中的数据

C# 使用ZipFile压缩列表框中的数据,c#,C#,我正在创建按钮点击事件,点击它将选择textbox1和comboBox1的数据。此外,它将从我提供的文件夹名中搜索特定的文件类型到textbox1。目前我使用listbox1作为容器来存储combobox和textbox中的值。现在我想压缩从listbox1获得的文件。我正在使用ZipFile压缩它。现在我陷入了如何调用listbox1中的所有数据进行压缩的困境 namespace WinDataStore { public partial class Form1 : Form

我正在创建按钮点击事件,点击它将选择textbox1和comboBox1的数据。此外,它将从我提供的文件夹名中搜索特定的文件类型到textbox1。目前我使用listbox1作为容器来存储combobox和textbox中的值。现在我想压缩从listbox1获得的文件。我正在使用ZipFile压缩它。现在我陷入了如何调用listbox1中的所有数据进行压缩的困境

namespace WinDataStore
{
    public partial class Form1 : Form
    {
        ComboBox comboBox;


        public Form1()
        {
            InitializeComponent();

            var daysOfWeek =
                new[] { "RED", "GREEN", "BLUE"
                         };           
             comboBox = new ComboBox
            {
                DataSource = daysOfWeek,
                Location = new System.Drawing.Point(180, 140),
                Name = "comboBox",
                Size = new System.Drawing.Size(166, 21),
                DropDownStyle = ComboBoxStyle.DropDownList
            };            
            this.Controls.Add(comboBox);
        }

        private void button1_Click(object sender, EventArgs e)
        {            
            FolderBrowserDialog folderBrowserDlg = new FolderBrowserDialog();
            folderBrowserDlg.ShowNewFolderButton = true;         
            DialogResult dlgResult = folderBrowserDlg.ShowDialog();
            if (dlgResult.Equals(DialogResult.OK))
            {                
                textBox1.Text = folderBrowserDlg.SelectedPath;              
               Environment.SpecialFolder rootFolder = folderBrowserDlg.RootFolder;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox1.Text))
            {
                //notification to user
                return;
            }

            string[] extensions = { ".xml",".ddg" };

            string[] dizin = Directory.GetFiles(textBox1.Text, "*.*",SearchOption.AllDirectories)
                .Where(f => extensions.Contains(new FileInfo(f).Extension.ToLower())).ToArray();

            listBox1.Items.AddRange(dizin);
            var comboBox = this.Controls["comboBox"] as ComboBox;                            
             string s = (string)comboBox.SelectedItem;
             listBox1.Items.Add(s);         


        }
    }
}

您想压缩文件或listbox1中的文本吗?listbox1包含来自组合框的数据,例如红色和文件路径C:\Users\com1.xml C:\Users\com2.xml,所以基本上我想压缩listbox1的eNotre内容有什么问题?您可以使用selecteditem,如果您想进行多次选择,请尝试
listbox1.SelectionMode=SelectionMode.MultiExtended