Execute function when upload is complete.

Last post 06-02-2009, 3:02 AM by trimmades. 18 replies.
Sort Posts: Previous Next
  •  05-18-2009, 1:35 PM 52283

    Execute function when upload is complete.

    Please forguve my ignorance.  I appreciate all your continued support!
     
    I am using, as an example, Start-uploading-manually.aspx.
     
    I am wanting to send an email when all the files are uploaded.  Where in the example code would i place this procedure, or what javascript API would i utilize, OR what ASP.net method would i use to make this happen?
     
    Looking at the example, i can't figure out where/how the control knows:  "Okay, I'm done... now do this...."
  •  05-18-2009, 3:21 PM 52293 in reply to 52283

    Re: Execute function when upload is complete.

    1. <script runat="server">   
    2.     protected override void OnInit(EventArgs e)   
    3.     {   
    4.         base.OnInit(e);   
    5.         Uploader1.FileUploaded += new UploaderEventHandler(Uploader_FileUploaded);   
    6.     }   
    7.   
    8.     void Uploader_FileUploaded(object sender, UploaderEventArgs args)   
    9.     {   
    10.            
    11.         Uploader uploader = (Uploader)sender;   
    12.   
    13.         //Copys the uploaded file to a new location.   
    14.         //args.CopyTo(path);   
    15.         //You can also open the uploaded file's data stream.   
    16.         //System.IO.Stream data = args.OpenStream();   
    17.     //Do something you want. For example, send emails here   
    18.     }   
    19. </script>  

     

    Line 17.
     
    Hope it helps.
     
    Keep me posted

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  05-21-2009, 10:59 AM 52388 in reply to 52293

    Re: Execute function when upload is complete.

    but what if you are uploading multiple files in the same process. and only want to send one email when all files are uploaded not when each file is uploaded??
  •  05-21-2009, 11:32 AM 52389 in reply to 52388

    Re: Execute function when upload is complete.

    Here's what i did to accomplish what you are talking about...
     
    dim uploadcount = 0

    Private Sub Uploader_FileUploaded(ByVal sender As Object, ByVal args As UploaderEventArgs)

    uploadcount += 1

     

     

     

    If uploadcount = 1 Then

    Email()

    End If

    'Response.Write(Uploader1.Items.Count)

    End Sub

  •  05-21-2009, 1:16 PM 52393 in reply to 52389

    Re: Execute function when upload is complete.

     
     
    Problem is I don't know how many items are going to be uploaded and I need to wait until ALL the items have been uploaded BEFORE I execute the function. Is there a way to accomplish that?
  •  05-21-2009, 2:48 PM 52406 in reply to 52393

    Re: Execute function when upload is complete.

    You're in luck! Thats exactly when the fileuploaded event gets fired.  After all files are uploaded.
  •  05-21-2009, 2:55 PM 52407 in reply to 52406

    Re: Execute function when upload is complete.

    Then really,  the first answer wouldn't work for an action for EACH file uploaded.
     
    Any thoughts on that?
  •  05-21-2009, 3:24 PM 52410 in reply to 52407

    Re: Execute function when upload is complete.

    Exactly.  From my experience, if you want to process something server-side after each upload, you must use the filevalidating event.
  •  05-21-2009, 3:28 PM 52411 in reply to 52406

    Re: Execute function when upload is complete.

    My test just shows that the

    FileUploaded

    event fires after every single upload is completed. I had it send me an email with a datetime stamp and I got 3 emails.
  •  05-21-2009, 3:36 PM 52412 in reply to 52411

    Re: Execute function when upload is complete.

    I should have been more clear.  The filevalidating gets fired DIRECTLY after the file has been uploaded and there are still items left in queue.  This gives you a sort-of parallel processing for the uploads.  The control continues to upload while your method is manipulating the last uploaded file. 
     
    The fileuploaded event(s) get fired after all files have been uploaded, once for each file.  I.E. When upload is complete.  So yes, it does get fired for each file, but not until all files have been uploaded.
  •  05-21-2009, 10:38 PM 52419 in reply to 52283

    Re: Execute function when upload is complete.

    Hi,
     
    Because too many customers require this feature,
     
    So we have add a new event 'UploadCompleted' for it ,
     
    Please download it again and check this sample :
     
    1. <%@ Page Language="C#" %>  
    2.   
    3. <%@ Register TagPrefix="CuteWebUI" Namespace="CuteWebUI" Assembly="CuteWebUI.AjaxUploader, Version=3.0.0.0, Culture=neutral, PublicKeyToken=bc00d4b0e43ec38d" %>  
    4. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">  
    5.   
    6. <script runat="server">  
    7.   
    8.     protected void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)   
    9.     {   
    10.         string msg = "You have uploaded " + args.Length + " files";   
    11.   
    12.         foreach (UploaderEventArgs arg in args)   
    13.         {   
    14.             msg += "\r\n" + arg.FileName + "," + arg.FileSize;   
    15.         }   
    16.   
    17.         Label1.Text = msg;   
    18.     }   
    19. </script>  
    20.   
    21. <html xmlns="http://www.w3.org/1999/xhtml">  
    22. <head runat="server">  
    23.     <title>UploadCompleted sample</title>  
    24. </head>  
    25. <body>  
    26.     <form id="form1" runat="server">  
    27.         <div>  
    28.             <CuteWebUI:Uploader runat="server" ID="Uploader1" MultipleFilesUpload="True" OnUploadCompleted="Uploader1_UploadCompleted">  
    29.             </CuteWebUI:Uploader>  
    30.             <pre><asp:Label runat="server" ID="Label1" />  
    31.             </pre>  
    32.         </div>  
    33.     </form>  
    34. </body>  
    35. </html>  
     
    Regards,
    Terry
     
  •  05-21-2009, 10:41 PM 52420 in reply to 52412

    Re: Execute function when upload is complete.

    as delamitry said, the order of the event is :
     
     
     
    client uploading file 1
     
    server FileValidating 1
     
    client uploading file 2
     
    server FileValidating 2
     
    client OnPostBack event
     
    server FileUploaded 1
    server FileUploaded 2
    server UploadCompleted([1,2])
     
    Regards,
    Terry
     
  •  05-23-2009, 3:38 PM 52441 in reply to 52419

    Re: Execute function when upload is complete.

    is there a javascript event that i can use after the progress bar disappears and before the FileUploaded method does its thing. When I am uploading several files the FileUploaded process could take a few seconds and I want to display to the enduser that processing is still going on and to hold tight.
  •  05-26-2009, 11:42 PM 52536 in reply to 52441

    Re: Execute function when upload is complete.

    Hi,
     
     
    Please check the OnPostBack event.
     
    Regards,
    Terry
     
  •  05-28-2009, 1:57 PM 52607 in reply to 52536

    Re: Execute function when upload is complete.

    Terry,
     
    Neither OnUploadCompleted nor UploadCompleted are members of Uploader class. That's what it throws when I define the property of add programatically an event.
     
    Does is still work?
     
    Francisco
     
  •  05-28-2009, 3:51 PM 52617 in reply to 52607

    Re: Execute function when upload is complete.

    fcogtz:
    Terry,
     
    Neither OnUploadCompleted nor UploadCompleted are members of Uploader class. That's what it throws when I define the property of add programatically an event.
     
    Does is still work?
     
    Francisco
     
     
    Francisco,
     
    OnUploadCompleted is added recently.
     
    Can you download the latest build then try again?
     
     

    asp.net Chat http://cutesoft.net/ASP.NET+Chat/default.aspx
    Web Messenger: http://cutesoft.net/Web-Messenger/default.aspx
    asp.net wysiwyg editor: http://cutesoft.net/ASP.NET+WYSIWYG+Editor/default.aspx
    asp wysiwyg html editor: http://cutesoft.net/ASP
    asp.net Image Gallery: http://cutesoft.net/ASP.NET+Image+Gallery/default.aspx
    Live Support: http://cutesoft.net/live-support/default.aspx

  •  05-29-2009, 5:41 AM 52629 in reply to 52617

    Re: Execute function when upload is complete.

    Terry,
     
    Newbie question:
     
    Not knowing how many files will be added, how do I programmatically generate an event to trigger the OnUploadCompleted event?
     
    Regards,
     
    Niclas
  •  06-01-2009, 12:22 AM 52672 in reply to 52629

    Re: Execute function when upload is complete.

     protected override void OnInit(EventArgs e)
     {
      base.OnInit(e);
      Uploader1.UploadCompleted += new UploaderBatchEventHandler(Uploader1_UploadCompleted);
     }

     void Uploader1_UploadCompleted(object sender, UploaderEventArgs[] args)
     {
      
     }

  •  06-02-2009, 3:02 AM 52722 in reply to 52672

    Re: Execute function when upload is complete.

    Sorry for my simple generic ASP.NET programming questions but this is the last step of my evaluation to use AjaxUploader in a small installation and I'm quite eager to solve my "UploadCompleted" needs.
     
    My question is: How do I supply the "OnUploadCompleted" event handler with the correct parameters?
     
    Each added file of course triggers the "OnFileUploaded" event. But how can I, in ASP.NET, build an array of the "UploaderEventArgs", keep it in memory and, when the end user clicks a specific "Submit button", call the "OnUploadCompleted" function, supplying my array of "UploaderEventArgs"?
     
    Perhaps your previous reply somehow answers my question?
     
    Many, many thanks.
     
    Regards,
     
    Niclas
     
     
     
     
View as RSS news feed in XML