January 3, 2023

Verify Zip file contents without extracting using C# + Selenium

  January 3, 2023

While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it.

One way to do this validation is by using extracting the contents to a folder and loop through each file names.

Given below is another way where we don't need to extract the zip file but can directly verify the files inside it.

For this we just need to provide the path of zip file and the file names that we need to check inside it.

First, we need to add below package to our solution.

using System.IO.Compression;

You can find it inside NuGet package manager in following names.


This will allow us to unlock different capabilities to work on a zip file using C# code.

A method to check the file names inside zip file is given below.

public bool verifyZipFileContent(string zipFilePath, string fileNameToCheck)
{
	bool foundFlag = false;
	using (ZipArchive archive = ZipFile.OpenRead(zipFilePath))
	{
		foreach (ZipArchiveEntry entry in archive.Entries)
		{
			if(entry.FullName== fileNameToCheck)
			{
				foundFlag = true;
			} 	   
		}
	}
	return foundFlag;
}

You can work around with this ZipArchive class according to your testing needs.
logoblog

Thanks for reading Verify Zip file contents without extracting using C# + Selenium

Newest
You are reading the newest post

No comments:

Post a Comment

Bookmark this website for more workarounds and issue fixes.

Verify Zip file contents without extracting using C# + Selenium

While doing automation testing, we may get a scenario where we need to download a zip file and to validate the contents inside it. One way t...