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

时间:2015-11-19 06:36:42

标签: c#

我正在创建按钮点击事件,点击它会选择textbox1和comboBox1的数据。此外,它将从我提供的文件夹名称中搜索特定的文件类型到textbox1。目前我使用listbox1作为容器来存储来自组合框和文本框的值。现在我想压缩我从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);         


        }
    }
}

0 个答案:

没有答案