<%@ Page Language="c#" %>
<%@ Register Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader" TagPrefix="CuteWebUI" %>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head runat="server">
    <title>Move a File Between Uploaders - v4 compatibility</title>
    <link rel="stylesheet" href="demo.css" type="text/css" />

    <script runat="server">
        void InsertMsg(string msg)
        {
            ListBoxEvents.Items.Insert(0, msg);
            ListBoxEvents.SelectedIndex = 0;
        }

        // v4 pattern: a file that arrives through one control is pushed into another
        // server-side, without a second round trip from the browser.
        void Uploader1_FileUploaded(object sender, UploaderEventArgs args)
        {
            InsertMsg("Uploader1 received " + args.FileName + " (" + args.FileSize + " bytes).");

            using (System.IO.Stream stream = args.OpenStream())
            {
                Attachments1.Upload(args.FileSize, args.FileName, stream);
            }

            InsertMsg("Pushed it into Attachments1 via Upload(size, name, stream).");
        }

        void Attachments1_AttachmentAdded(object sender, AttachmentItemEventArgs args)
        {
            InsertMsg("Attachments1 now holds " + args.Item.FileName + ".");
        }
    </script>
</head>
<body>
    <form id="Form1" method="post" runat="server">
        <div class="content">
            <a class="backlink" href="Default.aspx">&#8592; v4 compatibility demos</a>
            <h2>Move a File Between Uploaders</h2>
            <p>Upload through the first control; its handler streams the file straight into the
                attachment list using <code>Upload(size, name, stream)</code>.</p>

            <div class="note">
                This is the v4 sample verbatim. It exercises <code>args.OpenStream()</code> and the
                server-side <code>Upload()</code> overload together &mdash; the same pair a page uses
                to accept a file from one place and store it somewhere else.
            </div>

            <div class="panel">
                <p><strong>Uploader1</strong> &mdash; upload here:</p>
                <CuteWebUI:Uploader runat="server" ID="Uploader1"
                    InsertText="Uploader1 (Max 10M)"
                    OnFileUploaded="Uploader1_FileUploaded">
                    <ValidateOption MaxSizeKB="10240" />
                </CuteWebUI:Uploader>
            </div>

            <div class="panel">
                <p><strong>Attachments1</strong> &mdash; the file appears here:</p>
                <CuteWebUI:UploadAttachments runat="server" ID="Attachments1"
                    InsertText="Attachments1"
                    OnAttachmentAdded="Attachments1_AttachmentAdded" />
            </div>

            <div class="panel">
                <p>Server Trace:</p>
                <asp:ListBox runat="server" ID="ListBoxEvents" />
            </div>
        </div>
    </form>
</body>
</html>
