View Full Version : File Uploading problem

05-23-2009, 10:09 PM
I have a site under development that allows a punter to upload a single file to the web server. I use ASP.NET. The html fragment that allows the punter to select the file to upload is the well known
<input type=file id=file1 name=file1 runat="server" />
which enables the punter to select a file and populate a textbox with a path such as \Test documents\TestdoxA

The problem is that if this file is bigger than about 4 Mb, the upload process goes wrong and the result can look a mess to the punter.

At the point where \Test documents\TestdoxA appears in the textbox, (and before the punter presses the upload button) I would like to intervene and find the length of the file in bytes. Then, if it is too long, bring up a window to warn the guy off.

Can I do this with Javascript (or anyhow else, for that matter) ? If so, could someone point me at a bit of code that I could make a start with, please ?

05-24-2009, 02:42 AM
There is no sure fire cross browser way to do that. What you should do is inform the user that there is a file size limit and change your server side code, so that it does not present the user with "a mess", if she decides to upload files exceeding the limit, but with a user friendly message informing her about her mistake.