Example #1
0
    protected void btnDeleteSelectedFiles_Click(object sender, EventArgs e)
    {
        List <String> selectedFiles = new List <string>();
        int           StudentId     = 0;

        try
        {
            if (Request.QueryString["StudentId"] != null)
            {
                StudentId = Convert.ToInt32(Request.QueryString["StudentId"]);
            }

            objUser.SchoolId = Convert.ToInt16(hdn_SchoolID.Value);
            objUser.ClassId  = Convert.ToInt16(hdn_ClassID.Value);

            string   folderPath    = Server.MapPath("../GPXFiles/" + objUser.SchoolId + "/" + objUser.ClassId + "/" + StudentId);
            string[] uploadedFiles = System.IO.Directory.GetFiles(folderPath, "*.xml");
            int      deleteById    = Convert.ToInt32(Session["LoginId"]);
            foreach (GridViewRow rw in grdStudentDetails.Rows)
            {
                CheckBox chk_Delete  = rw.FindControl("chk_Delete") as CheckBox;
                Label    lblFileName = rw.FindControl("lblFileName") as Label;
                if (chk_Delete.Checked)
                {
                    //selectedFiles.Add(lblFileName.Text);
                    if (System.IO.File.Exists(folderPath + "/" + lblFileName.Text))
                    {
                        System.IO.File.Delete(folderPath + "/" + lblFileName.Text);

                        objStudent.UpdateFileDeleteFlag(objUser.SchoolId, objUser.ClassId, StudentId, lblFileName.Text, deleteById);
                    }
                }
            }
            _BindGrid();
            string popupScript = "'" + (string)GetLocalResourceObject("DeleteFile.SuccessMessage") + "'";
            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "successDelete(" + popupScript + ");", true);
        }
        catch
        {
            string popupScript = "'" + (string)GetLocalResourceObject("DeleteFile.ErrorMessage") + "'";
            ScriptManager.RegisterStartupScript(this, this.GetType(), Guid.NewGuid().ToString(), "successDelete(" + popupScript + ");", true);
        }
    }