Server side functionality upon upload of the last file

Mar 20, 2009 at 9:49 AM
Edited Mar 20, 2009 at 9:57 AM


Let me start by first saying that you have made an excellent tool for all open source users.
So here is my scenario...
I am successfully able to upload a bunch of files to the server. What I now need to be able to do is somehow let a server control know that the last file has been successfully uploaded so that I can start implementing some other functionalities with all the files at the sametime as opposed to one by one.
On client side this is made possible through javascript like this:
function FileStateChanged(uploader, file, httpStatus, isLast){
    Flajaxian.fileStateChanged(uploader, file, httpStatus, isLast);
        //Thats how I come to know its the last file in the queue; Is there something similar on server side?
I even tried implementing this through "OnFileReceived" event but somehow I'm unable to monitor the last file uploaded.
Do I have to resort to custom adapters? But I believe the "FileUploaderAdapter.ProcessFile" has similar functionility like FileReceived event.

Another concern:
I'm currently grabbing a listing of all files uploaded by saving them in an arraylist like this:
<fjx:FileUploader ID="FileUploader1" runat="server" JsFunc_FileStateChanged="FileStateChanged" OnFileReceived="FileReceived">
<fjx:FileSaverAdapter FolderName="UploadFolder" />



protected void FileReceived(object sender, FileReceivedEventArgs args){
Is there a better way to capture the listing of files uploaded from the queue?

And some insight on my assignment:
My project involves a web page whereby a user enters some relevant index information (a group of asp textboxes) and uploads a bunch relative of files/docs. The actual requirement consists of a drag and drop multiple file upload control through which a user can drag files from the local windows and drop on a web control that would create a listing of all files and an upload click would trigger the upload. After doing brief research I finally concluded that drag and drop functionality would be rather tedious in limited time constraints (Infact a good future enhancement for Flajaxian File Uploader) And so I resorted to this file upload control which turns out to be very useful.
But I'm sort of stuck here and need your help.
The basic concept that I need to implement is create a document in a COTS doc repository by inserting the index information in a database and add a bunch of files pertaining to that document in the file system. I've already created objects that would gives me index information and files that are uploaded.... and I've created the functionality of that would create this document in repository...
Somehow I have to create the linkage through which upon "last file upload" a server control and not client side can call this functionality (passing the objects as arguments)

Thank you for all the help....


Mar 20, 2009 at 3:27 PM
Why do you need to wait to the last record for saving the database? What is all records are ok and the last generates error? What is your plan for this scenario?
Mar 20, 2009 at 5:50 PM
Edited Mar 20, 2009 at 5:51 PM
If the last generates an error then it can be caught in the OnFileReceived event... The reason why I need to wait till the last record is because either there could be one file / multiple files uploaded for the set of index data and this as a whole comprises a potential document. Hence I need to trigger the process that creates this document [index data entered by user + set of file(s)] after the upload is complete. I do not want to or rather should not trigger this document creation process upon every file upload. this need to be triggered only after all the files have been uploaded.
And I want to integrate this functionality upon Upload button click.... since I cannot customize this upload on the server side... I'm kinda stuck here. I've seen a post where upload can be triggered from client-side but not from the server end. And i do not want to give user the headache of clicking one more button to trigger this document creation process (which otherwise would be really easy)
Another thing that I tried doing is create a hidden flag field that would be set upon last file uploaded (from client side javascript) and I monitored this field from the server OnFileReceived event so that when this field is set I would trigger this process but somehow the FileStateChanged JS updates the value after OnFileReceived event takes place.. so no luck there...
I hope this makes sense to you...
Mar 22, 2009 at 3:39 AM
Please get the latest version. FileReceivedEventArgs now has Index property (zero based file index) and IsLast flag indicating whether it is the last file.
Mar 25, 2009 at 10:35 PM
I've taken the latest version and will do some testing.... Many thanks for all the help sir...
Apr 8, 2009 at 7:59 PM
The above changes work really well... Here is another concern.
I have an asp label on my webpage that runs at server.
My FileReceived function looks like this:

protected void FileReceived(object sender, FileReceivedEventArgs args)
    // some custom code..
    if (args.isLast)
        //do some custom functioanlity for all the uploaded files...
        //this returns a boolean true or false....
        //based on success or failure I need to display the Success / Failure message on the label like this...
        this.lblMessage.Text = "<Message>"

Somehow this label isn't being set with the dynamic message.... I even tried requesting postback but in vain.
Any ideas of how can i set this label message in File Received event?
Apr 9, 2009 at 1:28 AM
You may want to spend some time studying what is client side and server side code and how the Ajax calls work. Without that it will be hard.
Apr 9, 2009 at 2:31 AM
You may be correct that I need to spend time understanding how AJAX works....... And I'm starting to learn all these concepts 
So are you saying that it's hard to implement what I'm trying to?  Is there any workaround?
Apr 9, 2009 at 4:43 AM
No Pshroff it's very easy, but if you try to use server side ajax call trying to update UI that means you don't understand the ajax call workflow. If you want to change label use client side JsFunc_FileStateChanged.

One advice I can give you is to observe the workflow with Fiddler and to watch each request. Then you will understand what is actually going on. In Fiddler use Inspectors. Upper right panel is the request, lower right panel is the response. I prefer to see it in Raw tab.
Apr 9, 2009 at 5:48 PM
I can set a message very easily using Js_FileStateChanged and upon last file upload.... But that isn't what I need.... what I need to be able to do is set a message on label control running on server depending on a boolean return from a custom function in FileReceived event handler.... 
Now I can fabricate the code myself.... if you can confirm any correct approach / route that I can take to implement this.
Thanks for all your help sir...
Apr 9, 2009 at 6:11 PM
An example of how to notify the client about custom server side condition is descibed in the documentation here:
Apr 9, 2009 at 7:00 PM
I have gone through those help files....FileNameDetermining handler does not help me much as the event is called upon every file being saved on the server... I need to be able to determine when the last file was recieved. Hence I resorted to FileRecieved event handler
protected void FileReceived(object sender, FileReceivedEventArgs args)
    // some custom code..
    if (args.isLast)
        //do some custom functioanlity for all the uploaded files...
        //this returns a boolean true or false....
        //based on success or failure I need to display the Success / Failure message on the label like this...
        this.lblMessage.Text = "<Message>"

Now here I come to know when the last file is recieved by the server and then I trigger custom server side code which works beautifully.... But then if I want to set some user message on a server label control or even on div or span on the client.... it doesn't work....

May be i'm misunderstanding the whole concept or something fairly easy....And i need help....
Apr 9, 2009 at 7:11 PM
You can change http status in FileReceived too
Apr 9, 2009 at 9:40 PM
I can set the http status in FileReceived even handler like this:
protected void FileReceived(object sender, FileReceivedEventArgs args)
    // some custom code..
    if (args.isLast)
        //do some custom functioanlity for all the uploaded files...
        //this returns a boolean true or false....
        //based on success or failure I need to display the Success / Failure message on the label like this...
        HttpContext.Current.Response.StatusCode = 550;         
        this.lblMessage.Text = "<Message>"

But I cannot access this status code in FileStateChanged as it executes before FileReceived event understandably....
How can I set a message on the web page from the FileRecieved event?
Apr 10, 2009 at 1:00 AM
Please get the latest and you will be able to track the status in FileReceived too
Apr 10, 2009 at 6:00 PM
Is there any way I can set any message for the User on the webpage from FileReceived event handler......?
Apr 12, 2009 at 2:11 AM
No because this is not an http Ajax request. This is the Flash file post request and it is quite limited for security reasons. But the status should be enough for you.
Apr 13, 2009 at 10:03 PM
Edited Apr 23, 2009 at 10:26 PM
How can I use this status to to give some confirmation to the user?
Do we have any sample code snippet?
Flajaxian.... could you please update me regarding this...
May 20, 2011 at 12:53 PM

Can we get that example? It's been 2 years.

Jul 6, 2011 at 2:50 PM

Use the ajax update panel and  the the Fileuploader tag like thie

<fjx:FileUploader ID="FileUploader1" runat="server"


See the last line: UseInsideUpdatePanel = "true"

Now set any label value and it will work.

Hope it will help you.


Ali Adravi

Jun 16, 2012 at 2:59 PM

I have been meaning to write about this for a while now. Didn't get the time.

First off, wonderful work. It seems to be immensely useful for me. The reason I say "seems" is that there seems to be a bug in the control. I am using this to upload albums/pictures to a site. For this to work for me I need to when the last the last file is being uploaded so that I can do a bit of post processing (like write album info to a DB etc.). But strangely, sometimes the islast gets triggered even when it is not the last file causing everything to go haywire. I have debugged it and it definately seems to be an issue. Doesn't happen all the time but quite frequently.

Any Ideas? Also there doesn't seem to be a file count functionality server side. Could you help me out with this? Would be much obliged. Thanks!