K
K
kvantuum2016-10-21 16:26:01
Android
kvantuum, 2016-10-21 16:26:01

How to show contents of archive in listview?

I clicked on the button to select an archive for example winrar, and after I clicked on the "Open" button, the contents of the selected archive should be displayed in my listview1, how to do it? 4b43fcbc1c734ef3a983a5b0864d884d.PNG
Yes, even if I want to add my simple text document (empty) to the archive, then I click add to the same winrar, and when I select Open with, I select the arivator that is on the picture, and txt with its size and weights should be displayed by columns in my archive.
Here is the code I have at the moment:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Collections;
using System.IO.Compression;
using System.Reflection;
using System.Drawing;
using System.Linq;
using System.IO;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace easywin
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Filter = "archieve files (*.zip)|*.zip";
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string filename = openFileDialog1.FileName;
                textBox1.Text = filename;
            }
//здесь должен находится код, который показывает файлы в архиве
            using (ZipArchive archive = ZipFile.OpenRead(textBox1.Text))
            {
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
                    {
                        ListViewItem txtItem = new ListViewItem(entry.FullName);
                        listView1.Items.Add(txtItem);
                    }
                }
            }
        }
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            textBox1.Enabled = false;
        }
        private void listView1_MouseClick(Object sender, MouseEventArgs e)
        {
        }
    }
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question