0

Possible Duplicate:
How check file size on upload

Ok, I got everything working and running, but now I need to restrict the file people send me via form to 500kb, at client side. I understood you need a 3-party plugin? Is there no way to do it via aspx?

If a plugin must be used: any suggestions to a good guide?

I'm using 3 files for my form: .aspx, .aspx.vb, web.config

If any other detail needed please let me know! I'm stuck on this, one step away from finishing this form....

Thank you.

Community
  • 1
  • 1
pelleg
  • 19
  • 1
  • 2
  • 8

3 Answers3

1

No, there is no way to do it via pure ASP.NET.

There a lots of commercial and non-commercial tools available. If your page is html 5, the easiest way to go might be to use jQuery.

If Flash is an option, check swfupload.

Here is a Javascript solution that might work.

Community
  • 1
  • 1
Olaf
  • 10,049
  • 8
  • 38
  • 54
0

Normally you set max upload in web.config. You can not check client-side without using a third-party tool.

Set it in web.config:

<system.webServer>
    <security>
        <requestFiltering>
            <requestLimits maxAllowedContentLength="524288"/>
        </requestFiltering>
    </security>
</system.webServer>

Problem is that you can't catch that client-side. You can however redirect the user if size is larger:

Catching “Maximum request length exceeded”

Community
  • 1
  • 1
Asken
  • 7,679
  • 10
  • 45
  • 77
  • this will restrict the total file size uploaded(instead of individual file size restriction [considering multiple file upload]) for entire website(rather than for a particular page particular file uploader), if I am not wrong.. – techBeginner Feb 16 '12 at 13:29
  • a "multiple file upload" is still submitting one file at a time (unless using flash or the likes) storing it on the server temporarily. it's not packaging it client side and THEN uploading it. – Asken Feb 16 '12 at 13:33
0

Try this

int fileSize = FileUpload1.PostedFile.ContentLength; 
 // Allow only files less than 512000 bytes (approximately 500kb (1024 = 1kb)(500*1024)) to be uploaded.            if (fileSize < 512000)            {
}
Sanjay Goswami
  • 1,386
  • 6
  • 13