FileUpload control - file size detection

E

E. Kwong

Is it possible to obtain the file size at the moment when the file path/name
populates the textbox portion of the FileUpload control?

Thx
 
B

Brennan Stehling

The HTML markup to do file upload is the INPUT element with "file" set
as the TYPE. You can read the specifications on it here.

http://www.w3.org/TR/html4/interact/forms.html

Unfortunately it does not support a file size limit with an attribute
on that markup element. That would be an obvious feature, but perhaps
it is not allowed due to security concerns although the size should be
a safe value to expose to an untrusted website. This is touchy because
it is one of the few features of a web browser which gives you access
to the user's file system.

I just browsed a site I use which has an upload features and used
Firefox's Firebug add-on to browse the DOM for the upload form and it
did not show the size of the file I had selected.

If there is a way to limit file size for uploads I would also like to
know it.

Brennan Stehling
http://brennan.offwhite.net/blog/
 
M

Michael D. Ober

If you have access to the web-site's configuration file, you can limit the
upload size via the Web.config file as follows:

<system.web>
<httpRuntime maxRequestLength="<max size in KB>"/>
</system.web>

Mike Ober.
 
S

Steve C. Orr [MVP, MCSD]

That works but not at the moment the filename is put in the upload box as
the original poster requested.

I don't know of any way to meet that requirement other than a thick client
such as a windows forms component (with the appropriate permissions) or an
ActiveX control.

--
I hope this helps,
Steve C. Orr
MCSD, MVP, CSM
http://SteveOrr.net
 
M

Michael D. Ober

Agreed - it doesn't answer OPs original question, but it can at least block
arbitrarily large files from being uploaded, which I suspect was the intent.

Mike.
 
S

Steve C. Orr [MVP, MCSD]

Yes I've thought about that but security is the main problem.
By default click once applications don't have much access to the user's hard
drive.

--
I hope this helps,
Steve C. Orr,
MCSD, MVP, CSM, ASPInsider
http://SteveOrr.net
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top