#region Uploading file on the click of upload button
    protected void UploadButton_Click(object sender, EventArgs e)
    {

        if (txtiCareNo.Text == "")
        {
            lblStatus.Text = "Please enter the iCare Number ; File NOT uploaded";
        }
        else
        {
            string stPathtoCreate = "~/Uploads/" + txtiCareNo.Text+"-"+txtAccountNo.Text;

            if (!Directory.Exists(stPathtoCreate))
            {
                Directory.CreateDirectory(Server.MapPath(stPathtoCreate));

                //mtdCreateFolderWithiCareNo();
                if (fUpload.HasFile)
                {
                    try
                    {
                        // if (fUpload.PostedFile.ContentType == "application/application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
                        if (fUpload.FileName != "")
                        {
                            if (fUpload.PostedFile.ContentLength < 10000000)
                            {
                                string filename = Path.GetFileName(fUpload.FileName);
                                fUpload.PostedFile.SaveAs(Server.MapPath(stPathtoCreate) + "/" + filename);
                                lblStatus.Text = "Upload status: File uploaded!";
                            }
                            else
                                lblStatus.Text = "Upload status: The file has to be less than 10 MB!";
                        }
                        else
                            lblStatus.Text = "Upload status: Only JPEG files are accepted!";
                    }
                    catch (Exception ex)
                    {
                        lblStatus.Text = "Upload status: The file could not be uploaded. The following error occured:" + ex.Message;
                    }
                }
            }
            else
            {
                lblStatus.Text = "Folder of this iCare No already exists. Please Check";
            }

            mtdFillingGridviewWithFilesInFolder();
        }
    }
    #endregion

    public void mtdFillingGridviewWithFilesInFolder()
    {
        DataTable dtFileInfo = new DataTable();
        dtFileInfo.Columns.Add("File/s Uploaded", typeof(string));
        dtFileInfo.Columns.Add("Delete", typeof(string));


        foreach (string strFile in Directory.GetFiles(Server.MapPath("~/Uploads/" + txtiCareNo.Text + "-" + txtAccountNo.Text)))
        {
            FileInfo fi = new FileInfo(strFile);

            dtFileInfo.Rows.Add(fi.Name,"Delete");

        }

        //string[] filePaths = Directory.GetFiles(Server.MapPath("~/Uploads/"+txtiCareNo.Text+"-"+txtAccountNo.Text));
        //List<ListItem> files = new List<ListItem>();

        //foreach (string filePath in filePaths)
        //{
        //    files.Add(new ListItem(Path.GetFileName(filePath), filePath));
        //}

        grdUploaded.DataSource = dtFileInfo;
        grdUploaded.DataBind();
        
    }
    
    protected void grdUploaded_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "Download")
        {
            Response.Clear();
            Response.ContentType = "application/octect-stream";
            Response.AppendHeader("Content-disposition", "filename=" + e.CommandArgument);
            Response.TransmitFile("~/Uploads/" + txtiCareNo.Text+"-"+txtAccountNo.Text+ "/" + e.CommandArgument);
            Response.End(); 

        }
        
    }
    protected void lnkDelete_Click(object sender, EventArgs e)
    {
        string filePath = (sender as LinkButton).CommandArgument;
        File.Delete(filePath);
        Response.Redirect(Request.Url.AbsoluteUri);
    }