using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.OracleClient;
using System.IO;
//using Ejada.SharpSsh;
using System.Threading;
using System.Diagnostics;
//using Ejada.SharpSsh.jsch;
using System.Net;
using Renci.SshNet;
using Renci.SshNet.Sftp;
using System.Collections.Generic;


public partial class Business_AutomaticClaims : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        //string filePath = ConfigurationManager.AppSettings["CPS_Outgoing"];
        //string[] nameofFiles = Directory.GetFiles(filePath);
        //for (int i = 0; i < nameofFiles.Length; i++)
        //    ;// labelFileName.Text = labelFileName.Text + "</br>" + nameofFiles[i];

        if (!IsPostBack)
        {
            loadFiles();
            loadCPSFilesList();
        }
    }
    private void loadCPSFilesList()
    {
        ddlCPSPFiles.Items.Clear();
        DirectoryInfo di = new DirectoryInfo(ConfigurationSettings.AppSettings["MD5EXEPATH"]);
        FileInfo[] rgFiles = di.GetFiles("*.CPS");
        foreach (FileInfo fi in rgFiles)
        {
            if (!fi.Name.Substring(fi.Name.Length - 8).Contains("-MD5.cps"))
                ddlCPSPFiles.Items.Add(fi.Name);
        }
    }
    private void loadFiles()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_dir_files";

        oracom.Parameters.Add("p_dir_list", OracleType.Cursor).Direction = ParameterDirection.Output;

        OracleDataAdapter da = new OracleDataAdapter(oracom);
        DataSet ds = new DataSet();
        da.Fill(ds);

        ddlFiles.DataSource = ds;
        ddlFiles.DataBind();

        oracon.Close();
    }

    private string getDir()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_claim_dir";

        oracom.Parameters.Add("p_dir", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.ExecuteNonQuery();
        oracon.Close();

        string a = oracom.Parameters["p_dir"].Value.ToString();
        return a;
    }

    private string getVirtualDir()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "poslookup_getter.get_claim_dir_out";

        oracom.Parameters.Add("p_dir", OracleType.VarChar, 250).Direction = ParameterDirection.Output;

        oracom.ExecuteNonQuery();
        oracon.Close();

        string a = oracom.Parameters["p_dir"].Value.ToString();
        return a;
    }

    protected void btnLoad_Click(object sender, EventArgs e)
    {
        if (ddlFiles.Items.Count > 0)
        {
            load();
            Session["PostAllSamaClaim"] = "Y";
            ScriptManager.RegisterClientScriptBlock(this, typeof(string), "new window",
                       "window.open('../Business/GLPosting.aspx','Redirect')", true);
         
        }
        else
            lblError.Text = "There are no files";
    }

    private void load()
    {
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "samaclaims.loadsamaclaims";

        oracom.Parameters.Add("filepath", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("filename", OracleType.VarChar).Direction = ParameterDirection.Input;

        //oracom.Parameters["filepath"].Value = "RECONSS_CPS_IN";
        oracom.Parameters["filepath"].Value = "CLAIM_FILES_DIR";
        oracom.Parameters["filename"].Value = ddlFiles.SelectedValue;

        oracom.ExecuteNonQuery();
        oracon.Close();
        lblError.ForeColor = System.Drawing.Color.DarkGreen;
        lblError.Text = "loading Completed";
    }

    private void generate_CPS()
    {
        string error = "";
        string DBConnection = Helper.dbConnection();

        OracleConnection oracon = new OracleConnection(DBConnection);
        oracon.Open();

        OracleCommand oracom = new OracleCommand();
        oracom.Connection = oracon;

        oracom.CommandType = CommandType.StoredProcedure;
        oracom.CommandText = "samaclaims.gensamaclaims";

        oracom.Parameters.Add("filepath", OracleType.VarChar).Direction = ParameterDirection.Input;
        oracom.Parameters.Add("p_ONfile_name", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_OFFfile_name", OracleType.VarChar, 250).Direction = ParameterDirection.Output;
        oracom.Parameters.Add("p_res_code", OracleType.Number).Direction = ParameterDirection.Output;

        oracom.Parameters["filepath"].Value = "RECONSS_CPS_OUT";// Change to sysparam - make it generic        

        oracom.ExecuteNonQuery();
        oracon.Close();
        string a = oracom.Parameters["p_res_code"].Value.ToString();
        string onfileName = oracom.Parameters["p_ONfile_name"].Value.ToString();
        string offfileName = oracom.Parameters["p_OFFfile_name"].Value.ToString();

        if (a == "0")
        {
            if (onfileName.Trim().Length != 0 || offfileName.Trim().Length != 0)
            {
                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                lblError.Text = "Generating Completed";

                string md5FilePath = ConfigurationManager.AppSettings["MD5EXEPATH"];


                if (downLoadFileFromSFTP(ref error))
                {
                    foreach (FileInfo f in new DirectoryInfo(ConfigurationManager.AppSettings["MD5EXEPATH"]).GetFiles("*.cps"))
                    {
                        if (!f.Name.Equals(onfileName) && !f.Name.Equals(offfileName))
                        {
                            try
                            {
                                f.Delete();
                            }
                            catch (Exception ex)
                            {
                            }
                        }
                        //if (!f.Name.Equals(fileName.Replace("ON", "OFF").Insert(fileName.Length - 3, "_edited")))
                        //f.Delete();

                    }
                    /*sat*/
                    // File.Move(filePath + FileName, md5FilePath + FileName);

                    if (onfileName.Trim().Length != 0)
                    {
                        byte[] array = File.ReadAllBytes(md5FilePath + onfileName);
                        if (array.Length > 1)
                        {
                            byte[] newArray = new byte[array.Length - 1];
                            Array.Copy(array, newArray, array.Length - 1);
                            File.WriteAllBytes(md5FilePath + onfileName, newArray);
                        }
                    }
                    //File.Move(filePath + offFileName, md5FilePath + offFileName);
                    if (offfileName.Trim().Length != 0)
                    {

                        byte[] array_off = File.ReadAllBytes(md5FilePath + offfileName);
                        if (array_off.Length > 1)
                        {
                            byte[] newArray_off = new byte[array_off.Length - 1];
                            Array.Copy(array_off, newArray_off, array_off.Length - 1);
                            File.WriteAllBytes(md5FilePath + offfileName, newArray_off);
                        }

                    }
                    /*end */
                    //RunMD5(FileName);
                    //FileUtilityDLL.CPSFileReceiver cfr =
                    //    new FileUtilityDLL.CPSFileReceiver(downloadPath, fileName);claim_process.pks

                    //lnkFile.NavigateUrl = downloadVirtualPath + fileName;    
                    ////lnkFile.NavigateUrl = downloadVirtualPath + "PONC20140608170343.cps"; 
                    //lnkFile.Text = "Download Generated File : " + fileName;
                    //lnkFile.Visible = true;
                    lblError.ForeColor = System.Drawing.Color.DarkGreen;
                    lblError.Text = "Generated";
                }
                else
                    lblError.Text = error;
            }
            else
                lblError.Text = "no claims are generated";

        }
        else
        {
            lblError.Text = "no claims are generated";

        }
    }
    private void generate_MDS()
    {
        string fileName;
        string md5FilePath = ConfigurationManager.AppSettings["MD5EXEPATH"];
        string md5exe = ConfigurationManager.AppSettings["MD5EXE"];
        //File.Move(filePath + ddlCPSPFiles .SelectedValue , md5FilePath + ddlCPSPFiles .SelectedValue );
        //File.Move(filePath + "PONC20140907144442.cps", md5FilePath + "PONC20140907144442.cps");
        //Process.Start(md5exe, FileName);  
        //Process.Start(md5exe, "PONC20140907144442.cps");
        //Response.AppendHeader("Content-Disposition", "attachment; filename=" + "PONC20140907144442-MD5.cps" + "");
        //Response.TransmitFile(md5FilePath + "PONC20140907144442-MD5.cps");

        Process.Start(md5exe, ddlCPSPFiles.SelectedValue);
        Thread.Sleep(2000);
        if (File.Exists(md5FilePath + ddlCPSPFiles.SelectedValue.Insert(ddlCPSPFiles.SelectedValue.Length - 4, "-MD5")))
        {
            File.Delete(md5FilePath + ddlCPSPFiles.SelectedValue);
            fileName = ddlCPSPFiles.SelectedValue.Insert(ddlCPSPFiles.SelectedValue.Length - 4, "-MD5");
            Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName + "");
            Response.TransmitFile(md5FilePath + fileName);
            Response.End();
        }
        else
            lblError.Text = "MD5 File is not generated..";
    }

    protected void btnGenerate_Click(object sender, EventArgs e)
    {
        generate_CPS();
        loadCPSFilesList();

    }
    protected void writeCPS(string key)
    {
        try
        {

            //Pass the filepath and filename to the StreamWriter Constructor
            StreamWriter sw = new StreamWriter("C:\\ALINMA\\Alinma_Recon\\MD5\\PONC20140907144442_md5.cps");

            //Write a line of text
            sw.WriteLine(key);


            //Close the file
            sw.Close();
        }
        catch (Exception e)
        {
            Console.WriteLine("Exception: " + e.Message);
        }

    }
    protected string readCPS()
    {
        String line;
        string[] key;
        try
        {
            //Pass the file path and file name to the StreamReader constructor
            StreamReader sr = new StreamReader("C:\\ALINMA\\Alinma_Recon\\MD5\\PONC20140907144442_md5.cps");

            //Read the first line of text
            line = sr.ReadLine();
            key = line.Split(' ');


            //close the file
            sr.Close();
            //Console.ReadLine();
            return key[0];
        }
        catch (Exception e)
        {
            return "";
        }

    }
    protected void RunMD5(string fileName)
    {
        try
        {
            string md5FileName;
            string md5_dir = ConfigurationSettings.AppSettings["MD5EXE"];
            System.Diagnostics.Process.Start(md5_dir, fileName);

            //lblError.Text = "MD5 file generated successfully";

            bool finish = true;

            string filename, cps_p_dir, cps_iis;

            while (finish)
            {
                try
                {
                    md5FileName = fileName.Insert(fileName.Length - 4, "-MD5");
                    File.Move(ConfigurationSettings.AppSettings["CPS_P"] + "\\" + md5FileName,
                        ConfigurationSettings.AppSettings["CPS_P_IIS"] + "\\" + md5FileName);

                    finish = false;
                }
                catch (Exception exx)
                {

                }
            }

            finish = true;
            while (finish)
            {
                try
                {

                    File.Move(ConfigurationSettings.AppSettings["CPS_P"] + "\\" + fileName,
                        ConfigurationSettings.AppSettings["CPS_P_IIS"] + "\\" + fileName);
                    finish = false;
                }
                catch (Exception exx)
                {

                }
            }



        }
        catch (Exception ex)
        {
            lblError.Text = "File Not Generated. Error happened during the execution of the MD5 exe";
        }
    }
    protected void btnUpload_Click(object sender, EventArgs e)
    {
        string error = "";
        if (FileUpload1.HasFile)
        {
            //uploadFile();
            // if (CpyFileToUnix(ref error))
            var fileExt = System.IO.Path.GetExtension(FileUpload1.FileName).Substring(1);
            if (!fileExt.ToLower().Equals("cps"))
            {
                lblError.Text = "File extension not supported";
                return;
            }  
            if (uploadFileToSFTP(ref  error))
            {
                loadFiles();
                lblError.ForeColor = System.Drawing.Color.DarkGreen;
                lblError.Text = "Successfully Uploaded";
            }
            else
                lblError.Text = error;
        }
        else
            lblError.Text = "Please choose a file";
    }
    private bool CpyFileToUnix(ref string error)
    {
        string CPS_InComing = ConfigurationManager.AppSettings["CPS_InComing"];

        try
        {
            string uploadPath = //ConfigurationSettings.AppSettings["CPS_D"];
                            Server.MapPath("../UploadedFiles") + "\\";
            string fileName = uploadPath + FileUpload1.FileName.Replace(" ", "");
            if (!File.Exists(fileName))
            {

                FileUpload1.SaveAs(fileName);
                File.Move(fileName, CPS_InComing + "\\" + FileUpload1.FileName.Replace(" ", ""));
                // File.Delete(fileName);
                return true;
            }
            else
                return false;

        }
        catch (Exception ex)
        {
            error = ex.Message;
            return false;
        }

    }

    private bool uploadFileToSFTP(ref string error)
    {
        ExceptionUtility.LogEvent_Errors(0, "", "uploadFileToSFTP", "Start");

        string ftpServer = ConfigurationManager.AppSettings["SFTPServer"];

        string UserName,Pwd;
        if (ConfigurationSettings.AppSettings["SFTP_Encrypt"] as string == "NO")
        {
            UserName = ConfigurationSettings.AppSettings["SFTPUserName"] as string;
            Pwd = ConfigurationSettings.AppSettings["SFTPPwd"] as string;
        }
        else { 
         UserName =  DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPUserName"]);
            Pwd =  DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPPwd"]);

            ExceptionUtility.LogEvent_Errors(0, "", "uploadFileToSFTP", "sftp:"+ UserName.Substring(0,3)+":"+Pwd.Substring(0,3));

        }
      
        try
        {
            string onlyfileName = FileUpload1.FileName.Replace(" ", "");
            string uploadPath =  Server.MapPath("../UploadedFiles") + "\\";
            string fileName = uploadPath + onlyfileName;
            if (!File.Exists(fileName))
            {

                FileUpload1.SaveAs(fileName);
                ExceptionUtility.LogEvent_Errors(0, "", "uploadFileToSFTP", "File Save as " +fileName);

                string uploadPathVirtual = getDir();
               
                var methods = new List<AuthenticationMethod>();
                methods.Add(new PasswordAuthenticationMethod(UserName, Pwd));

                var con = new ConnectionInfo(ftpServer, 22, UserName, methods.ToArray());

                using (var client = new SftpClient(con))
                {
                    client.Connect();
                    Console.WriteLine("");
                    ExceptionUtility.LogEvent_Errors(0, "", "uploadFileToSFTP", "SftpClient Successfully Connected");

                    //string uploadfn = "Upload.txt";
                    client.ChangeDirectory(uploadPathVirtual);//change if required
                    using (var uplfileStream = System.IO.File.OpenRead(fileName))
                    {
  
                        client.UploadFile(uplfileStream, onlyfileName, true);
                        ExceptionUtility.LogEvent_Errors(0, "", "uploadFileToSFTP", onlyfileName + " Uploaded");

                        
                    }
                    client.Disconnect();
                }

                 using (var sshClient = new SshClient(con))
                 {
                        sshClient.Connect();
                        var cmd = sshClient.RunCommand("chmod 777 " + uploadPathVirtual + onlyfileName);
                        ExceptionUtility.LogEvent_Errors(0, "", "uploadFileToSFTP", onlyfileName+ " Permission granted");

                        var output = cmd.Result;

                        sshClient.Disconnect();
                  }
                
                File.Delete(fileName);

                ExceptionUtility.LogEvent_Errors(0, "", "uploadFileToSFTP", "End");

                return true;
            }
            else
                return false;

        }
        catch (Exception ex)
        {
            error = ex.Message;
            ExceptionUtility.LogException(ex);
            return false;
        }

    }

    //4th March commented by irfan and umer
    /*
    private bool uploadFileToSFTP_Commented(ref string error)
    {
        string ftpServer = ConfigurationManager.AppSettings["SFTPServer"];
        //string UserName = ConfigurationManager.AppSettings["SFTPUserName"];
        //string Pwd = ConfigurationManager.AppSettings["SFTPPwd"];
        //Sathish 09012018
        string UserName = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPUserName"]);
        string Pwd = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPPwd"]);

        try
        {
            string uploadPath = //ConfigurationSettings.AppSettings["CPS_D"];
                            Server.MapPath("../UploadedFiles") + "\\";
            string fileName = uploadPath + FileUpload1.FileName.Replace(" ", "");
            if (!File.Exists(fileName))
            {

                FileUpload1.SaveAs(fileName);
                SshExec objSSH = new SshExec(ftpServer, UserName, Pwd);


                string uploadPathVirtual = getDir();
                objSSH.Connect();
                Sftp oSftp = new Sftp(ftpServer, UserName, Pwd);
                oSftp.Connect();
                oSftp.Put(fileName, uploadPathVirtual);

                // oSftp.Put(" -permissions=775 -nopreservetime " + fileName,  uploadPathVirtual);
                objSSH.RunCommand("chmod 777 " + uploadPathVirtual + FileUpload1.FileName.Replace(" ", ""));
                oSftp.Close();
                objSSH.Close();
                File.Delete(fileName);
                return true;
            }
            else
                return false;

        }
        catch (Exception ex)
        {
            error = ex.Message;
            return false;
        }

    }
    */
    private bool downLoadFileFromSFTP(ref string error)
    {
        ExceptionUtility.LogEvent_Errors(0, "", "downLoadFileFromSFTP", "Start");

        string ftpServer = ConfigurationManager.AppSettings["SFTPServer"];

        
       //   string UserName = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPUserName"]);
       // string Pwd = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPPwd"]);
        string UserName, Pwd;
        if (ConfigurationSettings.AppSettings["SFTP_Encrypt"] as string == "NO")
        {
            UserName = ConfigurationSettings.AppSettings["SFTPUserName"] as string;
            Pwd = ConfigurationSettings.AppSettings["SFTPPwd"] as string;
        }
        else
        {
            UserName = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPUserName"]);
            Pwd = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPPwd"]);
        }

        string ftpDirectory = getVirtualDir(); //The directory in SFTP server where the files are present
         string LocalDirectory = ConfigurationManager.AppSettings["MD5EXEPATH"];

        try
        {
             var methods = new List<AuthenticationMethod>();
            methods.Add(new PasswordAuthenticationMethod(UserName, Pwd));

            var con = new ConnectionInfo(ftpServer, 22, UserName, methods.ToArray());

            
            using (var client = new SftpClient(con))
            {
                client.Connect();
                ExceptionUtility.LogEvent_Errors(0, "", "downLoadFileFromSFTP", "Connected");

                var FileList = client.ListDirectory(ftpDirectory);


            
            foreach (var file in FileList)
            {
                if (file.Name != "." && file.Name != ".." && file.Name != "Processed")
                {
                    if (!File.Exists(LocalDirectory + "/" + file.Name))
                    {
                        using (var fs = new FileStream(LocalDirectory + file.Name, FileMode.Create))
                        {
                            client.DownloadFile(file.FullName, fs);
                            ExceptionUtility.LogEvent_Errors(0, "", "downLoadFileFromSFTP", "Downloaded: " + file.FullName);
                            Thread.Sleep(100);
                        }
                    }
                    else
                        ExceptionUtility.LogEvent_Errors(0, "", "downLoadFileFromSFTP", "File Already Exist: " + file.FullName);
                }
            }

            client.Disconnect();
            }
            ExceptionUtility.LogEvent_Errors(0, "", "downLoadFileFromSFTP", "End");

            return true;
        }
        catch (Exception ex)
        {
            error = ex.Message + ex.InnerException;
            ExceptionUtility.LogException(ex);
            return false;
        }
    }

    //4th March commented by irfan and umer
    /*
    private bool downLoadFileFromSFTP(ref string error)
    {
        string ftpServer = ConfigurationManager.AppSettings["SFTPServer"];


        //string UserName = ConfigurationManager.AppSettings["SFTPUserName"];
        //string Pwd = ConfigurationManager.AppSettings["SFTPPwd"];
        string UserName = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPUserName"]);
        string Pwd = DecryptLibrary.DecryptLibrary.DecryptData(ConfigurationSettings.AppSettings["SFTPPwd"]);

        string ftpDirectory = getVirtualDir(); //The directory in SFTP server where the files are present
        //string LocalDirectory = ConfigurationManager.AppSettings["CPS_P"]; //Local directory where the files will be downloaded
        string LocalDirectory = ConfigurationManager.AppSettings["MD5EXEPATH"];

        try
        {
            SshExec objSSH = new SshExec(ftpServer, UserName, Pwd);
            objSSH.Connect();
            Sftp oSftp = new Sftp(ftpServer, UserName, Pwd);

            oSftp.Connect();
            ArrayList FileList = oSftp.GetFileList(ftpDirectory);
            FileList.Remove(".");
            FileList.Remove("..");          //Remove . from the file list
            FileList.Remove("Processed");   //Remove folder name from the file list. If there is no folder name remove the code.

            for (int i = 0; i < FileList.Count; i++)
            {
                if (!File.Exists(LocalDirectory + "/" + FileList[i]))
                {
                    oSftp.Get(ftpDirectory + "/" + FileList[i], LocalDirectory + "/" + FileList[i]);
                    Thread.Sleep(100);
                }
            }
            oSftp.Close();
            objSSH.Close();
            return true;
        }
        catch (SftpException ex)
        {
            error = ex.Message + ex.InnerException;

            return false;
        }
    }
    */
    private void uploadFile()
    {
        string uploadPath = ConfigurationSettings.AppSettings["CPS_D"];
        if (File.Exists(uploadPath + FileUpload1.FileName.Replace(" ", "")))
            lblError.Text = "file already exists";
        else
        {
            FileUpload1.SaveAs(uploadPath + FileUpload1.FileName.Replace(" ", ""));
            //FileUtilityDLL.CPSFileSender cfs =
            //    new FileUtilityDLL.CPSFileSender(uploadPath, FileUpload1.FileName.Replace(" ", ""));
            //loadFiles();
            lblError.ForeColor = System.Drawing.Color.DarkGreen;
            lblError.Text = "CPS File Uploaded...";// and being transfered to the files list. Please wait for a few seconds and refresh the page";
        }
    }

    protected void btnGeneratemd5_Click(object sender, EventArgs e)
    {
        generate_MDS();
    }
    protected void ddlFiles_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void btnDownload_Click(object sender, EventArgs e)
    {
        string md5FilePath = ConfigurationManager.AppSettings["MD5EXEPATH"];
        Response.AppendHeader("Content-Disposition", "attachment; filename=" + ddlCPSPFiles.SelectedValue);
        Response.TransmitFile(md5FilePath + ddlCPSPFiles.SelectedValue);
        Response.End();
    }
}
