views:

1463

answers:

3

Hi,

Im using a fileupload control for my asp application and it throws a HttpException when the file upload size is bigger than the max request length.

As far i understand the fileupload will open a memory stream to a file once the file browse dialog is closed but there is no way of knowing when the dialog is closed so that I can make a decision whether to abort the upload.

Does anyone know of a way of examining the file size before the upload begins?

Spam.

+1  A: 

If you leave file upload to built-in Asp.Net mechanisms, then an upload will fail if the request size is larger than the max size set in web.config (or machine.config).

You can solve that by writing your own HttpHandler and first check the size of the request, and then handle the request data in your code.

devio
A: 

I doubt there is a universal way to check file size on client-side ( I mean for all browsers ), as usually client-side script does not have access to file system.

I used to catch the exception on server side and then notice the user when programming in classic ASP.

Liwen
A: 

This control will let you upload any file size. I use it and it is very very handy. I believe the source is there if you want it.

http://www.brettle.com/neatupload

DrG