protected void DownloadPhoto(object sender, EventArgs e)
{
List<string> refil = new List<string>();
try
{
using (ZipFile zip = new ZipFile())
{
zip.AddDirectoryByName("Files");
foreach (GridViewRow row in grdStudentList.Rows)
{
string filePath = (row.FindControl("img_photo") as Image).ImageUrl;
Label lblRegd = (Label)row.FindControl("lbl_studregid");
string filePath1 = Server.MapPath(filePath);
string sourcepath = filePath;
string TargetPath = Server.MapPath("~/LogManager/");
string sourceFile = System.IO.Path.Combine(sourcepath, filePath);
string destFile = System.IO.Path.Combine(TargetPath, lblRegd.Text + System.IO.Path.GetExtension(filePath1));
if (File.Exists(filePath1))
{
System.IO.File.Copy(filePath1, destFile, true);
refil.Add(destFile);
zip.AddFile(destFile, "BatchPhotos");
}
}
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);
}
}
catch (SqlException ex)
{
}
catch (System.IO.IOException ex)
{
}
catch (Exception ex)
{
}
finally
{
for (int i = 0; i <= refil.Count - 1; i++)
{
FileInfo file = new FileInfo(refil[i]);
if (file.Exists)
{
file.Delete();
}
}
Response.End();
}
}
No comments:
Post a Comment