I'm new to C# I'm trying to display search result from textbox to a listview on button_click.
Here is my code:
private void button1_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
listView1.Refresh();
string[] filePaths = Directory.GetFiles(@textBox1.Text, "*.zip");
string txtSearch = textBox2.Text;
foreach (var filePath in filePaths)
{
using (ZipArchive archive = ZipFile.OpenRead(filePath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
var position = entry.Name.IndexOf(
txtSearch,
StringComparison.InvariantCultureIgnoreCase);
if (position > -1)
{
listView1.Items.Add(entry.Name);
}
else
{
MessageBox.Show(
"FILE NOT FOUND",
"ERROR",
MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
}
}
}'
This code works if its a single folder contain other archives but with this folder structure: folderA(contains): FolderA1, FolderA2. FloderA1(contains): , FolderA1.1, FolderA1.2, FolderA1.3 and FolderA1.4 FloderA1.1 to 1.4(each contains): , Folder and lot of archives(.zip and .rar) FloderA2(contains): FolderA2.1, FolderA2.2 and FolderA2.3. FloderA2.1 to 2.3(each contains): lot of archives(.zip and .rar)
how do i use this code to search for files with particular extension to list even when any of the folders=filepath.
thanks in advance.