0

I have a file up-loader. I do not want to check the size of the file on server side, I need some kind of listener to get the size uploaded each period and check if it is allowed or not using Javascript and I am using an asp.net file uploader.

3 Answers 3

1

AFAIK there is no javascript event to check client-side for a filesize when uploading... and since you don't want to check this server-side the answer is browser-dependent in the sense that it needs a client-side javascript API capable of what you want.

You could use HTML5+Javascript (File API) for this... but beware: there are borwsers/browser versions that don't supoport this... see details and samples:

Sign up to request clarification or add additional context in comments.

2 Comments

I want to use it with asp.net all i need is the event and i need to know how to cancel uploading using asp.net or javascript
@EslamSoliman AFAIK there is no javascript event to check for a filesize when uploading... what you ask is browser-dependent in the sense that it needs a javascript API capable of what you want - that is exactly what the links above provide!
0

i think you cannot fetch the file size detail from javascript, what you can do, you can access it from server side with the help of script block . like this.

protected void btnFileUpload1_Click(object sender, EventArgs e)
{
    int filesize; 
    filesize = FileUpload1.PostedFile.ContentLength; //to get the Size of uploaded files 
    if(filesize > yourMaxLength)
    {
           string errorScript = "<script type=\"text/javascript\">" +
         "alert('Invalid File, you cannot upload file exceeding ' + filesize );" +
                      "</script>";
         ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", errorScript);
    }
   else
   {
         //proceeed with upolad successful operation 
   }
}

Comments

0

Uploadify is a nice plugin for jQuery for uploading files, it has a pretty nice collection of callbacks on events, with full info about the file that is being uploaded and the progress of the upload.

1 Comment

it's using flash as it know the size before uploading it from the server side

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.