using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class app_custom_screens_IHConfiguration_account_information_upload_license : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        bool failed = false; string json = ""; 
        HttpFileCollection fileCollection = Request.Files;
        if (fileCollection.Count > 0)
        {
            HttpPostedFile file = fileCollection[0];
            //string path = Context.Server.MapPath("~/license-files");
            string path = ConfigurationManager.AppSettings.Get("licenseFolder");
            if (path != null)
            {
                Guid g = Guid.NewGuid();
                string filename = Path.Combine(path, g.ToString() + ".bin");
                file.SaveAs(filename);

                json = "{\"status\":\"OK\", \"fileGUID\":\"" + g.ToString() + "\"}";
                Response.Clear();
                Response.ContentType = "application/json; charset=utf-8";
                Response.Write(json);
                Response.End();
            }
            else
            {
                failed = true; 
            }
        }
        else
        {
            failed = true; 
        }

        if (failed)
        {
            json = "{\"status\":\"FAILED\"}";
            Response.Clear();
            Response.ContentType = "application/json; charset=utf-8";
            Response.Write(json);
            Response.End();
        }
    }
}