Namespace To USED:-
using System.IO;
using Ionic.Zip;
using System.Collections.Generic;
using (ZipFile zip = new ZipFile())
{
string filePath = ""; int i = 0;
foreach (DataGridItem dg in dgStudentDOc.Items)
{
if (Convert.ToInt32(ViewState["Count"]) == 0)
{
zip.AddDirectoryByName("Files");
string ImageURL = hdStudentIMG.Value;
if (ImageURL != "")
{
filePath = Server.MapPath("URL" + ImageURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ','_') + "");
}
}
filePath = "";
string PassportURL = hdPassport.Value;
if (PassportURL != "" && PassportURL != "Image URL Path.extension Name")
{
filePath = Server.MapPath("../../"+PassportURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ', '_') + "");
}
}
filePath = "";
string VisaURL = hdVisa.Value;
if (VisaURL != "" && VisaURL != "Image URL Path.extension Name")
{
filePath = Server.MapPath(VisaURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ', '_') + "");
}
}
filePath = "";
string EmiratesIDURL = hdEmiratesID.Value;
if (EmiratesIDURL != "" && EmiratesIDURL != "Image URL Path.extension Name")
{
filePath = Server.MapPath(EmiratesIDURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ', '_') + "");
}
}
#endregion
ViewState["Count"] = Convert.ToInt32(ViewState["Count"]) + 1;
}
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss") + "_" + lblStudnetName.Text.Replace(' ', '_'));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
Response.End();
}
using System.IO;
using Ionic.Zip;
using System.Collections.Generic;
using (ZipFile zip = new ZipFile())
{
string filePath = ""; int i = 0;
foreach (DataGridItem dg in dgStudentDOc.Items)
{
if (Convert.ToInt32(ViewState["Count"]) == 0)
{
zip.AddDirectoryByName("Files");
string ImageURL = hdStudentIMG.Value;
if (ImageURL != "")
{
filePath = Server.MapPath("URL" + ImageURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ','_') + "");
}
}
filePath = "";
string PassportURL = hdPassport.Value;
if (PassportURL != "" && PassportURL != "Image URL Path.extension Name")
{
filePath = Server.MapPath("../../"+PassportURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ', '_') + "");
}
}
filePath = "";
string VisaURL = hdVisa.Value;
if (VisaURL != "" && VisaURL != "Image URL Path.extension Name")
{
filePath = Server.MapPath(VisaURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ', '_') + "");
}
}
filePath = "";
string EmiratesIDURL = hdEmiratesID.Value;
if (EmiratesIDURL != "" && EmiratesIDURL != "Image URL Path.extension Name")
{
filePath = Server.MapPath(EmiratesIDURL);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Files" + lblStudnetName.Text.Replace(' ', '_') + "");
}
}
#endregion
ViewState["Count"] = Convert.ToInt32(ViewState["Count"]) + 1;
}
}
Response.Clear();
Response.BufferOutput = false;
string zipName = String.Format("Zip_{0}.zip", DateTime.Now.ToString("yyyy-MMM-dd-HHmmss") + "_" + lblStudnetName.Text.Replace(' ', '_'));
Response.ContentType = "application/zip";
Response.AddHeader("content-disposition", "attachment; filename=" + zipName);
zip.Save(Response.OutputStream);
Response.End();
}