Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

how can i find a file's size before uploading it? using javscript with activex is not supported by many browsers. but still it is possible on client side (gmail does it in all browsers when you attach a file on client side itself). plz help...

thanks & regards, AR
Posted

but that requires sending the file to the server. there is a client side method for this that gmail uses, but i cant find how...
 
Share this answer
 
GMail's attachment upload uses Flash to find the size and display the progress.

Here is another one that does the same thing: SWFUpload[^]
 
Share this answer
 
swfupload is doing the job just the way i wanted it...thanks a lot
 
Share this answer
 
you cant use javascript but you can use ajax.
-------------------

Answer 2:

Use something like this:

if (FileUploadControl.HasFile)
            {
              double FileSize = FileUploadControl.PostedFile.ContentLength;
              double VerifyFileSize = FileSize / 1024 / 1024;
              bool Status = false;
             
              if (VerifyFileSize > 1)// where "1 MB" is the size
              {
                  Status = true;
              }

                FileSizeStatusLabel.Text = FileSize.ToString() + " " + (Status ? "to big" : "size ok");
            }


I mentioned Ajax to get rid of the post back. However, as I said you cant get it using client js
 
Share this answer
 
v4
As far as I can tell, an iFrame is doing the actual submission of the file, while you look at the rest of the page. I'm not sure how it's working out the file size, I did some googling and couldn't find any info. Perhaps they are faking it ?
 
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