Hi suhaas121,
Refer modified code.
protected void downimg_Click(object sender, EventArgs e)
{
HiddenField2.Value = name();
string svalue = HiddenField2.Value;
string path = @"~/Source images/" + svalue ;
string[] files = Directory.GetFiles(Server.MapPath(path));
using (ZipFile zip = new ZipFile())
{
zip.AddFiles(files, "sourceImages");
zip.Save(@"C:\Users\user\Desktop\sourceImages.zip");
}
}
Check this example. Now please take its reference and correct your code.
HTML
<asp:TextBox runat="server" ID="txtvalue" CssClass="form-control" />
<asp:LinkButton ID="downimg" OnClick="downimg_Click" runat="server"
CssClass="btn btn-primary btn-rounded btn-icon" Width="50px"
ToolTip="Download images"><i class="fa fa-download"></i></asp:LinkButton>
Namespaces
C#
using System.IO;
using Ionic.Zip;
VB.Net
Imports System.IO
Imports Ionic.Zip
Code
C#
protected void downimg_Click(object sender, EventArgs e)
{
string svalue = txtvalue.Text;
string path = @"~/Source images/" + svalue;
string[] files = Directory.GetFiles(Server.MapPath(path));
using (ZipFile zip = new ZipFile())
{
zip.AddFiles(files, "sourceImages");
zip.Save(@"C:\Users\user\Desktop\sourceImages_" + svalue.Replace(" ", "_") + ".zip");
}
}
VB.Net
Protected Sub downimg_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim svalue As String = txtvalue.Text
Dim path As String = "~/Source images/" & svalue
Dim files As String() = Directory.GetFiles(Server.MapPath(path))
Using zip As ZipFile = New ZipFile()
zip.AddFiles(files, "sourceImages")
zip.Save("C:\Users\user\Desktop\sourceImages_" & svalue.Replace(" ", "_") & ".zip")
End Using
End Sub