Click here to Skip to main content
15,889,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using AjaxFileUpload Control what i want that when user try to upload the file ,
the control first should check that is it exceeding the limit defined by the admin i.e user can only uploads 5 files after that he/she should have to delete to upload another file that means it can only upload 5 files no more than that.

So basically when user try to upload, the control just interrupt the process and display that you have exceed the file limits, delete one of the files to upload new one.

And all that i want in AjaxFileUpload because it uploads file without posting back the whole page.

1) i can limit the number of files to uploaded in queue
2) types of uploading files can also be restricted

the one thing i am missing and i don't know is stated above.

so geeks run your mind and give answer .........
Posted
Comments
Naresh.Thakor 2-Apr-14 1:26am    
Hi Narendra,
just follow this link http://www.dotnetfox.com/articles/ajax-fileupload-or-multiple-fileupload-with-progress-example-in-Asp-Net-1081.aspx that will be usefull.

1 solution

Ajax Upload Control HTML:
ASP.NET
<ajaxctrl:asyncfileupload id="AsyncFileUpload1" runat="server" uploaderstyle="Traditional" xmlns:ajaxctrl="#unknown">
                                            OnClientUploadError="uploadErrorHandler" OnUploadedComplete="ProcessUpload" OnClientUploadStarted="uploadStarted"
                                            Width="110px" ClientIDMode="Static" Style="position: absolute; z-index: 2; opacity: 0;
                                            filter: alpha(opacity=0); border: solid 1px red;" ToolTip="Upload Photo" ThrobberID="UpdateProgress1" /></ajaxctrl:asyncfileupload>


Handle EventFunctions:

C#
function uploadErrorHandler(sender, args) {
       //  alert('Invalid file/filesize "'+args.get_fileName()+'"!');
     }


C#
function uploadStarted(sender, args) {
    if (validateFileExtension(args.get_fileName())) {
        var fileSize = args.get_length();
        if (parseInt(fileSize) > 3800000) {
            alert('File exceeds the file size limit.Maximum size is 19MB');
            args.set_cancel(true);
            return false;
        }
    }
    else {
        alert("Invalid file '" + args.get_fileName() + "'.Supported file types are '.jpg, .jpeg, .gif, .png, .bmp' ");
        args.set_cancel(true);
        return false;
    }
}


C# Code:

C#
protected void ProcessUpload(object sender, AjaxControlToolkit.AsyncFileUploadEventArgs e)
       {
           Boolean isValidFile = Utility.isValidFile(e.FileName, new String[] { ".gif", ".jpg", ".bmp", ".png" });

           if (isValidFile)
           {
              //Write your code
           }
           else
           {
               ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "img", "alert('Invalid Image File!');", true);
           }
       }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900