<%@ Page Title="Single File Upload" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" %>
<%@ Register Assembly="AjaxUploader" Namespace="AjaxUploader.Controls" TagPrefix="au" %>
<script runat="server">
    protected void Uploader1_FileUploaded(object sender, AjaxUploader.Events.FileUploadedEventArgs e)
    {
        // Public demo: save OUTSIDE the web root (App_Data is never served), under a
        // server-generated name - a public site must not become an open file host.
        var savedName = System.Guid.NewGuid().ToString("N") + System.IO.Path.GetExtension(e.FileName ?? "");
        new AjaxUploader.Services.UploadService().CopyFile(e.FileGuid, "~/App_Data/DemoSaves/" + savedName);
        lblSaved.Text = "Your handler ran: saved <code>" + Server.HtmlEncode(e.FileName)
            + "</code> as <code>App_Data/DemoSaves/" + savedName + "</code> (" + e.FileSize + " bytes)";
    }
</script> 
<asp:Content ID="TitleContent" ContentPlaceHolderID="TitleContent" runat="server">Single File Upload - AjaxUploader v5.3 Demos</asp:Content>
<asp:Content ID="HeaderContent" ContentPlaceHolderID="HeaderTitle" runat="server">Single File Upload</asp:Content> 
<asp:Content ID="BodyContent" ContentPlaceHolderID="MainContent" runat="server"> 
<div class="demo-card"> <div class="demo-card-header">Single File Upload</div> <div class="demo-card-body"> <p class="demo-description"> <strong>The simplest possible AjaxUploader setup.</strong> One file at a time, auto-upload
 on selection, progress bar. This is the default behavior when <code>AllowMultiple</code> is
 not set or set to <code>false</code>. Everything else - chunked transport, drag-and-drop,
 cloud upload, encryption, validation - is opt-in on top of this baseline.
 </p>
 <div class="demo-expect"><strong>What you should see:</strong> the picker accepts exactly one file. Selecting a second file replaces the first in the queue.</div> <au:AjaxFileUpload ID="Uploader1" runat="server"
 ButtonText="Select a File"
 AutoUpload="true"
 AutoPostBack="true"
 OnFileUploaded="Uploader1_FileUploaded"
 ShowProgress="true" /> <div class="alert alert-success py-2 px-3 small mt-3" role="status"><asp:Label ID="lblSaved" runat="server" Text="Nothing saved yet - select a file; the page posts back automatically and your FileUploaded handler saves it." /></div> <div class="code-panel"> <pre><code>&lt;%@ Register Assembly="AjaxUploader" Namespace="AjaxUploader.Controls" TagPrefix="au" %&gt;

&lt;au:AjaxFileUpload ID="Uploader1" runat="server"
 ButtonText="Select a File"
 AutoUpload="true"
 AutoPostBack="true"
 OnFileUploaded="Uploader1_FileUploaded"
 ShowProgress="true" /&gt;

// Uploads land in a temp store; SAVE them in FileUploaded.
// AutoPostBack fires it automatically when the upload finishes.
protected void Uploader1_FileUploaded(object sender,
    AjaxUploader.Events.FileUploadedEventArgs e)
{
    new AjaxUploader.Services.UploadService()
        .CopyFile(e.FileGuid, "~/uploads/" + e.FileName);
}</code></pre> </div> </div>
</div> 
</asp:Content>
