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;

public partial class CPS_Download : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            loadFiles();
            links.Visible = false;
        }
    }

    protected void btnSearch_Click(object sender, EventArgs e)
    {
        try
        {
            bool finish = true;
            while (finish)
            {
                try
                {

                    File.Copy(ConfigurationSettings.AppSettings["CPS_P"] + "\\" + ddlFiles.SelectedValue, 
                        ConfigurationSettings.AppSettings["CPS_P_IIS"] + "\\" + ddlFiles.SelectedValue, true);
                    finish = false;
                }
                catch (Exception exx)
                {

                }
            }


            lnkSAMA.NavigateUrl = ConfigurationSettings.AppSettings["CPS_P_IIS_V"] + ddlFiles.SelectedValue;
            
            
            
            
            links.Visible = true;

            loadFiles();
        }
        catch (Exception ex)
        {
            lblError.Text = "File Not Generated. Error happened during the execution of the MD5 exe";
        }

    }

    private void loadFiles()
    {
        ddlFiles.Items.Clear();
        DirectoryInfo di = new DirectoryInfo(ConfigurationSettings.AppSettings["CPS_P"]);
        FileInfo[] rgFiles = di.GetFiles("*.CPS");
        foreach (FileInfo fi in rgFiles)
        {
            ddlFiles.Items.Add(fi.Name);
        }
    }

}
