Refer the below sample code for your reference and implement it in your code as per your logic.
Here i used to get the images from list you can use your code logic to get images from other references.
HTML
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" EmptyDataText="No files available">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
<asp:Label ID="lblFilePath" runat="server" Text='<%# Eval("Value") %>' Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Image">
<ItemTemplate>
<asp:Image ID="imgImage" runat="server" Height="100px" Width="100px" ImageUrl='<%#Eval("Value") %> ' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Text" HeaderText="File Name" />
</Columns>
</asp:GridView>
<br />
<asp:Button ID="btnDownload" runat="server" Text="Download" OnClick="DownloadFiles" />
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
/*Your image Binding code as per your code logic logic */
List<string> images = new List<string>();
images.Add("https://static.flickr.com/66/199481236_dc98b5abb3_s.jpg");
images.Add("https://static.flickr.com/75/199481072_b4a0d09597_s.jpg");
images.Add("https://static.flickr.com/57/199481087_33ae73a8de_s.jpg");
string[] filePaths = images.ToArray();
List<ListItem> files = new List<ListItem>();
foreach (string filePath in filePaths)
{
files.Add(new ListItem(Path.GetFileName(filePath), filePath));
}
GridView1.DataSource = files;
GridView1.DataBind();
}
}
protected void DownloadFiles(object sender, EventArgs e)
{
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
zip.AddDirectoryByName("Files");
List<string> imagespath = new List<string>();
foreach (GridViewRow row in GridView1.Rows)
{
if ((row.FindControl("chkSelect") as CheckBox).Checked)
{
string filePath = (row.FindControl("lblFilePath") as Label).Text;
string file = GetImage(filePath);
imagespath.Add(file);
zip.AddFile(file, "Files");
}
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
string folderPath = Server.MapPath("TempImages/");
foreach (var path in imagespath)
{
if (File.Exists(path))
{
File.Delete(path);
}
}
Response.End();
}
}
private string GetImage(string url)
{
string filename = Path.GetFileName(url);
string folderPath = Server.MapPath("TempImages/");
string saveLoc = folderPath + filename;
if (!Directory.Exists(folderPath))
{
Directory.CreateDirectory(folderPath);
}
using (WebClient wc = new WebClient())
{
byte[] fileBytes = wc.DownloadData(url);
System.IO.File.WriteAllBytes(saveLoc, fileBytes);
}
return saveLoc;
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
'Your image Binding code as per your code logic logic
Dim images As List(Of String) = New List(Of String)()
images.Add("https://static.flickr.com/66/199481236_dc98b5abb3_s.jpg")
images.Add("https://static.flickr.com/75/199481072_b4a0d09597_s.jpg")
images.Add("https://static.flickr.com/57/199481087_33ae73a8de_s.jpg")
Dim filePaths As String() = images.ToArray()
Dim files As List(Of ListItem) = New List(Of ListItem)()
For Each filePath As String In filePaths
files.Add(New ListItem(Path.GetFileName(filePath), filePath))
Next
GridView1.DataSource = files
GridView1.DataBind()
End If
End Sub
Protected Sub DownloadFiles(ByVal sender As Object, ByVal e As EventArgs)
Using zip As ZipFile = New ZipFile()
zip.AlternateEncodingUsage = ZipOption.AsNecessary
zip.AddDirectoryByName("Files")
Dim imagespath As List(Of String) = New List(Of String)()
For Each row As GridViewRow In GridView1.Rows
If (TryCast(row.FindControl("chkSelect"), CheckBox)).Checked Then
Dim filePath As String = (TryCast(row.FindControl("lblFilePath"), Label)).Text
Dim file As String = GetImage(filePath)
imagespath.Add(file)
zip.AddFile(file, "Files")
End If
Next
Response.Clear()
Response.BufferOutput = False
Dim zipName As String = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss"))
Response.ContentType = "application/zip"
Response.AddHeader("content-disposition", "attachment; filename=" & zipName)
zip.Save(Response.OutputStream)
Dim folderPath As String = Server.MapPath("TempImages/")
For Each path In imagespath
If File.Exists(path) Then
File.Delete(path)
End If
Next
Response.[End]()
End Using
End Sub
Private Function GetImage(ByVal url As String) As String
Dim filename As String = Path.GetFileName(url)
Dim folderPath As String = Server.MapPath("TempImages/")
Dim saveLoc As String = folderPath & filename
If Not Directory.Exists(folderPath) Then
Directory.CreateDirectory(folderPath)
End If
Using wc As WebClient = New WebClient()
Dim fileBytes As Byte() = wc.DownloadData(url)
System.IO.File.WriteAllBytes(saveLoc, fileBytes)
End Using
Return saveLoc
End Function
Screenshot
