protected void btnDownloadSelected_Click(object sender, EventArgs e) { string msgmodal = ""; try { DataTable tablePIDS = new DataTable(); tablePIDS.Columns.Add("ID", typeof(int)); DataTable table = new DataTable(); table.Columns.Add("ID", typeof(string)); table.Columns.Add("VALUE", typeof(string)); foreach (GridViewRow row in gvProgram_ListDetails.Rows) { if (row.RowType != DataControlRowType.Header) { CheckBox checkRow = row.FindControl("checkRow") as CheckBox; TextBox txtProgramIDS = row.FindControl("txtProgramIDS") as TextBox; if (checkRow.Checked) { List <string> PIDS = new List <string>(); List <string> lPrograms = txtProgramIDS.Text.Split(',').ToList <string>(); foreach (string lProgram in lPrograms) { if (!PIDS.Contains(lProgram.Trim())) { if (UDFLib.ConvertIntegerToNull(lProgram.Trim()) != null) { tablePIDS.Rows.Add(Convert.ToInt32(lProgram.Trim())); table.Rows.Add(gvProgram_ListDetails.DataKeys[row.RowIndex].Values[0].ToString(), lProgram.Trim()); PIDS.Add(lProgram.Trim()); } } } } } } if (tablePIDS.Rows.Count <= 0) { msgmodal = String.Format("alert('Vessel(s) not selected for downloading training items!.')"); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", msgmodal, true); return; } DataSet ds_ProgramList_Scheduled = BLL_LMS_Training.GET_FileList_To_Sync(tablePIDS); int rowindex = 0; string zipFile = ""; List <string> zips = new List <string>(); foreach (DataRow row in ds_ProgramList_Scheduled.Tables[0].Rows) { zips.Add(row["ITEM_PATH"].ToString()); rowindex++; } if (zips.Count > 0) { var ac = Server.MapPath("~/Uploads/TrainingItems/"); zipFile = BLL_LMS_Training.RAR(Server.MapPath("~/Uploads/TrainingItems/"), zips); int lLastValue = BLL_LMS_Training.Ins_Program_Sync(table, Convert.ToInt32(Session["USERID"])); string DownloadFileName = "AttachedProgramDocuments" + "_" + DateTime.Now.Day + "-" + DateTime.Now.Month + "-" + DateTime.Now.Year + "_" + DateTime.Now.Hour + "h" + DateTime.Now.Minute + "m" + DateTime.Now.Second + "s" + ".rar"; if (File.Exists(Server.MapPath("~/Uploads/TrainingItems/" + zipFile))) { File.Move(Server.MapPath("~/Uploads/TrainingItems/" + zipFile), Server.MapPath("~/Uploads/Temp/" + DownloadFileName)); ResponseHelper.Redirect("~/Uploads/Temp/" + DownloadFileName, "blank", ""); } else { msgmodal = String.Format("alert('Files not present on the Server.')"); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", msgmodal, true); } BindPrograms(); BindHistorySelection(); ddlSyncDate.SelectedIndex = -1; } } catch (Exception ex) { msgmodal = String.Format("Error :\n " + ex.ToString()); ScriptManager.RegisterStartupScript(Page, Page.GetType(), "", msgmodal, true); } }