Re: getting file modified date from CuteWebUI_AjaxUploader_OnSelect

  •  05-29-2011, 9:03 PM

    Re: getting file modified date from CuteWebUI_AjaxUploader_OnSelect

    Hi Roughan,
     
    Please try the example below. It shows you how to get the original file path.
     
    <%@ Page Language="C#" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

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

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            Uploader1.FileUploaded += new UploaderEventHandler(Uploader_FileUploaded);
            ButtonPostBack.Click += new EventHandler(ButtonPostBack_Click);
        }

        void ButtonPostBack_Click(object sender, EventArgs e)
        {
            InsertMsg("You clicked a PostBack Button.");
        }

        void SubmitButton_Click(object sender, EventArgs e)
        {
            InsertMsg("You clicked the Submit Button.");
            InsertMsg("You have uploaded " + uploadcount + " files.");
        }

        int uploadcount = 0;

        void Uploader_FileUploaded(object sender, UploaderEventArgs args)
        {
            uploadcount++;

            Uploader uploader = (Uploader)sender;
            //TextBox1.Text = args.
            InsertMsg("File uploaded! " + args.FileName + ", " + args.FileSize + " bytes.");

            //Copys the uploaded file to a new location.
            //args.CopyTo(path);
            //You can also open the uploaded file's data stream.
            //System.IO.Stream data = args.OpenStream();
        }

        protected override void OnPreRender(EventArgs e)
        {
            SubmitButton.Attributes["hasfile"] = Uploader1.File == null ? "false" : "true";
            
            base.OnPreRender(e);
        }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
                <h2>
                    ManualStartUpload</h2>
                <asp:TextBox ID="TextBox1" runat="server" Width="240px"></asp:TextBox><CuteWebUI:UploadPersistedFile ItemTextTemplate="" runat="server" UploadType="IFrame"
                    ManualStartUpload="true" ID="Uploader1" InsertText="Upload File">
                </CuteWebUI:UploadPersistedFile>
                <br />
                <br />
                <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"
                    Text="Submit" OnClick="SubmitButton_Click" />
                <br />
                <br />
                <div>
                    Server Trace:
                    <%=DateTime.Now.ToUniversalTime().Ticks %>
                    <br />
                    <asp:ListBox runat="server" ID="ListBoxEvents" Width="400"></asp:ListBox>
                </div>
                <br />
                <br />
                <asp:Button ID="ButtonPostBack" Text="This is a PostBack button" runat="server" />
            </div>

            <script type="text/javascript">
        
        function submitbutton_click()
        {
            var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');
            var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');
            if(!window.filesuploaded)
            {
                if(uploadobj.getqueuecount()>0)
                {
                    uploadobj.startupload();
                }
                else
                {
                    if(submitbutton.getAttribute("hasfile")=="true")
                    {
                        return true;
                    }
                    alert("Please browse files for upload");
                }
                return false;
            }
            window.filesuploaded=false;
            return true;
        }
        function CuteWebUI_AjaxUploader_OnPostback()
        {
            window.filesuploaded=true;
            var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');
            submitbutton.click();
            return false;
        }
        function CuteWebUI_AjaxUploader_OnQueueUI(list)
        {
            var tb=document.getElementById('<%=TextBox1.ClientID %>');
            if(list.length==0)
            {
                tb.value="";
            }
            if(list.length==1)
            {
                //tb.value=list[0].FileName
                
                //IFrame mode:
                var uploadobj=document.getElementById('<%=Uploader1.ClientID %>');
                var tasks=uploadobj.internalobject.tasks;
                for(var p in tasks)
                {
                    var task=tasks[p];
                    if(task&&task.uploadid)
                    {
                        tb.value=task.file1.value;
                    }
                }
            }
            return false;
        }
            </script>

        </form>
    </body>
    </html>
     
    Regards,
     
    ken
     
View Complete Thread