public DataTable GetCertificate(string batchid)
{
object ob = null;
try
{
string Q = @"select certificatepath,Studentregid from Mst_Student_Certificate where BATCH_CODE=@Batch_id";
SqlParameter[] para = { new SqlParameter("@Batch_id", batchid) };
DataTable dt = Luminious.DataAcessLayer.SqlHelper.ExecuteDataTable(Luminious.Connection.Configuration.ConnectionString, CommandType.Text, Q, para);
if (dt != null && dt.Rows.Count > 0)
{
using (ZipFile zip = new ZipFile())
{
for (int i = 0; i < dt.Rows.Count; i++)
{
string fileName = dt.Rows[i]["certificatepath"].ToString();
string filePath = Server.MapPath("~/View/CertificationAgency/KIACertificate/FinalCertificates/" + fileName);
if (File.Exists(filePath))
{
zip.AddFile(filePath, "Certificates");
}
}
//if (zip.Count > 0)
//{
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=(Certificates)" + zipName);
zip.Save(Response.OutputStream);
Response.End();
//}
//else
//{
// ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('There are no certificate available');", true);
//}
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "msg", "alert('There are no certificates available for download');", true);
}
}
catch (SqlException ex)
{
ExceptionHandler.WriteException(ex.Message);
}
catch (Exception ex)
{
ExceptionHandler.WriteException(ex.Message);
}
finally
{
if (ob != null)
{
ob = null;
}
}
return null;
}
No comments:
Post a Comment