UploadereventArgs

Last post 12-07-2011, 7:03 AM by Anonymous. 4 replies.
Sort Posts: Previous Next
  •  12-06-2011, 5:54 AM 71808

    UploadereventArgs

     I want to save the files when clicking the save button. not onFileUploaded. Now files are uploaded the the folder even if I don't save the complete form. And when I add images they will be uploaded, but if I remove an image that I did not want to upload it is not deleted in the folder '~/Library/nieuws/'
    What do I have to do to make this work? Are the files in the ajaxuploader accessible in the code behind? because I also want to resize them before saving.  
    1. protected void uplImages_FileUploaded(object sender, UploaderEventArgs args)  
    2.     {  
    3.         args.CopyTo("~/Library/nieuws/" + args.FileName);  
    4.     }  
    Thx,
  •  12-06-2011, 6:06 AM 71809 in reply to 71808

    Re: UploadereventArgs

    Hi dbots,
     
    If you want to upload the file when click on the submit button to submit the form, please refer to example below.
     
     
    You can find the source code of this example in the download package.
     
    Regards,
     
    Ken 
  •  12-07-2011, 3:13 AM 71828 in reply to 71809

    Re: UploadereventArgs

    Hi,
     
    The images are only saved in the temp folder. On btnSave click I only get the message 'select images'. The code is copied from the example. Am I overlooking something?
     
    ASPX Code:
     
    1. <asp:UpdatePanel ID="udpImages" runat="server" UpdateMode="Conditional">  
    2.                         <ContentTemplate>  
    3.                             <cc2:UploadAttachments ID="uplImages" OnFileUploaded="uplImages_FileUploaded" runat="server"  
    4.                                 TempDirectory="~/Library/temp_upload" MaxFilesLimit="5" FileTooLargeMsg="Bestand is te groot! Max. 1 MB."  
    5.                                 MultipleFilesUpload="true" ShowProgressInfo="false" ShowProgressBar="false" InsertText="Kies uw afbeeldingen"  
    6.                                 MaxFilesLimitMsg="U mag maximaal 5 afbeeldingen uploaden" RemoveButtonText="Verwijder"  
    7.                                 ShowFileIcons="true">  
    8.                                 <ValidateOption MaxSizeKB="1000" AllowedFileExtensions="jpg,png,gif,jpeg,bmp" />  
    9.                             </cc2:UploadAttachments>  
    10.                         </ContentTemplate>  
    11.                     </asp:UpdatePanel>  
    12. <asp:Button runat="server" ID="btnSave" onclick="btnSave_Click" Text="Bewaren" OnClientClick="return submitbutton_click()" />  
     Javascript code:
     
    1. <script type="text/javascript">  
    2.   
    3.     function submitbutton_click() {  
    4.         var submitbutton = document.getElementById('<%=btnSave.ClientID %>');  
    5.         var uploadobj = document.getElementById('<%=uplImages.ClientID %>');  
    6.         if (!window.filesuploaded) {  
    7.             if (uploadobj.getqueuecount() > 0) {  
    8.   
    9.                 uploadobj.startupload();  
    10.             }  
    11.             else {  
    12.                 var uploadedcount = parseInt(submitbutton.getAttribute("itemcount")) || 0;  
    13.                 if (uploadedcount > 0) {  
    14.                     return true;  
    15.                 }  
    16.                 alert("Select images");  
    17.             }  
    18.             return false;  
    19.         }  
    20.         window.filesuploaded = false;  
    21.         return true;  
    22.     }  
    23.   
    24.       
    25. </script>  
    C# code:
     
    1. int uploadcount = 0;  
    2.   
    3.     protected override void OnPreRender(EventArgs e)  
    4.     {  
    5.         btnSave.Attributes["itemcount"] = uplImages.Items.Count.ToString();  
    6.   
    7.         base.OnPreRender(e);  
    8.     }  
    9.   
    10. public void uplImages_FileUploaded(object sender, UploaderEventArgs args)  
    11.     {  
    12.   
    13.         uploadcount++;  
    14.         Uploader uploader = (Uploader)sender;  
    15.         /*args.CopyTo("~/Library/nieuws/" + args.FileName);*/  
    16.           
    17.           
    18.     }  
    19.   
    20. public void btnSave_Click(object sender, EventArgs e)  
    21.     {  
    22.     }  
     
  •  12-07-2011, 6:16 AM 71840 in reply to 71828

    Re: UploadereventArgs

    Hi dbots,
     
    Please try the example below. When you click on the submit button, the upload will start and the upload files will save into the "photos" folder in the button click event.
     
    <%@ 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">   
        protected void SubmitButton_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < Uploader1.Items.Count; i++)
            {
                Uploader1.Items[i].CopyTo("~/photos/" + Uploader1.Items[i].FileName);
            }
        }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Start uploading manually</title>
        <link rel="stylesheet" href="demo.css" type="text/css" />
    </head>
    <body>
        <form id="form1" runat="server">
            <div style="text-align: left">
                <CuteWebUI:UploadAttachments runat="server" ManualStartUpload="true" ID="Uploader1">
                </CuteWebUI:UploadAttachments>
                <br />
                <asp:Button runat="server" ID="SubmitButton" OnClientClick="return submitbutton_click()"
                    Text="Submit" OnClick="SubmitButton_Click" />
            </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();
    }
    return false;
    }
    window.filesuploaded=false;
    return true;
    }
    function CuteWebUI_AjaxUploader_OnPostback()
    {
    window.filesuploaded=true;
    var submitbutton=document.getElementById('<%=SubmitButton.ClientID %>');
    submitbutton.click();
    return false;
    }
            </script>
        </form>
    </body>
    </html>
     
    Regards,
     
    Ken 
  •  12-07-2011, 7:03 AM 71856 in reply to 71840

    Re: UploadereventArgs

    Hi,
     
    This works.
     
    thx 
View as RSS news feed in XML