<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Register Assembly="AjaxUploader" Namespace="AjaxUploader.Controls" TagPrefix="au" %>
<script runat="server">
    // Self-contained diagnostic for "upload succeeds but FileUploaded does not save".
    // Works with ANY 5.2.3 DLL build (uses no new properties). Every step reports.
    protected void Page_Load(object sender, EventArgs e)
    {
        var asm = typeof(AjaxUploader.Controls.AjaxFileUpload).Assembly;
        litEnv.Text = "<b>1. Environment</b><br/>DLL: " + Server.HtmlEncode(asm.Location)
            + "<br/>DLL written: " + System.IO.File.GetLastWriteTime(asm.Location)
            + "<br/>Has AutoPostBack property (new build): "
            + (typeof(AjaxUploader.Controls.AjaxFileUpload).GetProperty("AutoPostBack") != null)
            + "<br/>Temp dir resolves to: " + Server.HtmlEncode(AjaxUploader.AjaxUploaderConfig.ResolvedTempDirectory)
            + "<br/>IsPostBack: " + IsPostBack;
        if (IsPostBack)
        {
            var posted = Request.Form[Uploader1.UniqueID];
            litPost.Text = "<b>2. Postback</b><br/>Hidden field posted: '"
                + Server.HtmlEncode(posted ?? "(NOTHING - the upload GUIDs never reached the server)") + "'";
        }
    }
    protected void Uploader1_FileUploaded(object sender, AjaxUploader.Events.FileUploadedEventArgs e)
    {
        var svc = new AjaxUploader.Services.UploadService();
        var info = svc.GetFileInfo(e.FileGuid);
        var savedName = Guid.NewGuid().ToString("N") + System.IO.Path.GetExtension(e.FileName ?? "");
        var savedPath = "~/uploads/" + savedName;
        string result;
        try
        {
            svc.CopyFile(e.FileGuid, savedPath);
            result = "SAVED: " + System.IO.File.Exists(Server.MapPath(savedPath))
                + " at " + Server.HtmlEncode(Server.MapPath(savedPath));
        }
        catch (Exception ex) { result = "SAVE FAILED: " + Server.HtmlEncode(ex.GetType().Name + " - " + ex.Message); }
        litEvent.Text = "<b>3. FileUploaded fired</b> guid=" + e.FileGuid
            + " name='" + Server.HtmlEncode(e.FileName ?? "(null)") + "' size=" + e.FileSize
            + " metaFound=" + (info != null) + "<br/>" + result + "<br/>";
    }
</script>
<!DOCTYPE html>
<html><body style="font-family:Segoe UI;max-width:760px;margin:2rem auto">
<h2>AjaxUploader save diagnostic</h2>
<form id="form1" runat="server">
    <asp:Literal ID="litEnv" runat="server" /><hr/>
    <p>Select one small, non-sensitive file. This page posts back automatically and reports the save result.</p>
    <au:AjaxFileUpload ID="Uploader1" runat="server" OnFileUploaded="Uploader1_FileUploaded" />
    <asp:Literal ID="litPost" runat="server" /><hr/>
    <asp:Literal ID="litEvent" runat="server" Text="<b>3.</b> FileUploaded has not fired on this request." />
</form>
</body></html>
