protected void btnDownload_Click(object sender, EventArgs e)
        {
            int    downloadID = int.Parse(((System.Web.UI.WebControls.WebControl)(sender)).Attributes["qid"]);
            string type       = ((System.Web.UI.WebControls.WebControl)(sender)).Attributes["istype"].ToString();
            string filePath   = string.Empty;

            if (type == "distributor")
            {
                if (downloadID > 0)
                {
                    PriceListDownloadsBO objDownload = new PriceListDownloadsBO();
                    objDownload.ID = downloadID;
                    objDownload.GetObject();
                    filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objDownload.FileName);
                }
            }

            if (type == "label")
            {
                if (downloadID > 0)
                {
                    LabelPriceListDownloadsBO objLabelDownload = new LabelPriceListDownloadsBO();
                    objLabelDownload.ID = downloadID;
                    objLabelDownload.GetObject();
                    filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objLabelDownload.FileName);
                }
            }
            if (!string.IsNullOrEmpty(filePath))
            {
                while (true)
                {
                    if (File.Exists(filePath))
                    {
                        string[] attachFilePath = { filePath };
                        try
                        {
                            FileInfo fileInfo   = new FileInfo(filePath);
                            string   outputName = System.Text.RegularExpressions.Regex.Replace(fileInfo.Name, @"\W+", "_");
                            outputName = System.Text.RegularExpressions.Regex.Replace(outputName, "_xlsx", ".xlsx");
                            Response.ClearContent();
                            Response.ClearHeaders();
                            Response.AddHeader("Content-Type", "application/vnd.ms-excel");
                            Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", outputName));
                            Response.AddHeader("Content-Length", (fileInfo.Length).ToString("F0"));
                            Response.TransmitFile(filePath);
                            Response.Flush();
                            Response.Close();
                            Response.BufferOutput = true;
                            //Response.End();
                        }
                        catch (Exception ex)
                        {
                            // Log the error
                            IndicoLogging.log.Error("Fail to download excel file.", ex);
                        }
                    }
                    break;
                }
            }
        }
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            int    id   = int.Parse(hdnSelectedID.Value);
            string type = this.hdnType.Value;

            if (type == "distributor")
            {
                PriceListDownloadsBO objPriceListDownload = new PriceListDownloadsBO(this.ObjContext);
                objPriceListDownload.ID = id;
                objPriceListDownload.GetObject();

                string filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objPriceListDownload.FileName);

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);

                    try
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            objPriceListDownload.Delete();
                            ObjContext.SaveChanges();
                            ts.Complete();
                        }
                    }
                    catch (Exception ex)
                    {
                        IndicoLogging.log.Error("Error occured while deleting distrinutor price list", ex);
                    }
                }
            }
            if (type == "label")
            {
                LabelPriceListDownloadsBO objLabelPriceListDownload = new LabelPriceListDownloadsBO(this.ObjContext);
                objLabelPriceListDownload.ID = id;
                objLabelPriceListDownload.GetObject();

                string filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objLabelPriceListDownload.FileName);

                if (File.Exists(filePath))
                {
                    File.Delete(filePath);

                    try
                    {
                        using (TransactionScope ts = new TransactionScope())
                        {
                            objLabelPriceListDownload.Delete();
                            ObjContext.SaveChanges();
                            ts.Complete();
                        }
                    }
                    catch (Exception ex)
                    {
                        IndicoLogging.log.Error("Error occured while deleting label price list", ex);
                    }
                }
            }
            this.PopulateControls();
        }