473,569 Members | 2,472 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Maximum file upload question

In ASP.Net (VS 2005), is there a way to limit the user to upload a
file up to certain size (say, I would like to limit the user to upload
at the maximum 1 meg of file) ?
Thank you
Nov 19 '07 #1
6 1720
Since there is no way for you to tell from the server-side how big the user's
file is, you simply check the UploadedFile object's size at the server and
reject it with the appropriate message to the user.

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com

"fi**********@g mail.com" wrote:
In ASP.Net (VS 2005), is there a way to limit the user to upload a
file up to certain size (say, I would like to limit the user to upload
at the maximum 1 meg of file) ?
Thank you
Nov 19 '07 #2
I suppose Peter was talking about HttpPostedFile. ContentLength property :)

--
WBR, Michael Nemtsev [.NET/C# MVP].
Blog: http://spaces.live.com/laflour

"fi**********@g mail.com" wrote:
In ASP.Net (VS 2005), is there a way to limit the user to upload a
file up to certain size (say, I would like to limit the user to upload
at the maximum 1 meg of file) ?
Thank you
Nov 19 '07 #3
re:
!I would like to limit the user to upload at the maximum 1 meg of file

Iy's very simple...

In web.config :

<httpRuntime maxRequestLengt h="1024"/>


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========
<fi**********@g mail.comwrote in message news:28******** *************** ***********@l22 g2000hsc.google groups.com...
In ASP.Net (VS 2005), is there a way to limit the user to upload a
file up to certain size (say, I would like to limit the user to upload
at the maximum 1 meg of file) ?
Thank you

Nov 19 '07 #4
re:
!Since there is no way for you to tell from the server-side how big the user's file is

There isn't any way to do that, but you can limit the maximum size for any uploaded file.
See my just-sent-in tip.


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========
"Peter Bromberg [C# MVP]" <pb*******@yaho o.NoSpamMaam.co mwrote in message
news:FD******** *************** ***********@mic rosoft.com...
Since there is no way for you to tell from the server-side how big the user's
file is, you simply check the UploadedFile object's size at the server and
reject it with the appropriate message to the user.

--Peter
"Inside every large program, there is a small program trying to get out."
http://www.eggheadcafe.com
http://petesbloggerama.blogspot.com
http://www.blogmetafinder.com

"fi**********@g mail.com" wrote:
>In ASP.Net (VS 2005), is there a way to limit the user to upload a
file up to certain size (say, I would like to limit the user to upload
at the maximum 1 meg of file) ?
Thank you

Nov 19 '07 #5
It should be noted that this entry will limit the size of all HTTP requests
for all pages controlled by that web.config. You can, however, put the
"upload file" page in its own sub-folder and put a web.config in that folder
with the appropriate settings. For example, you might also want to adjust
the timeout value to allow for slow uploads, etc.

I guess my point is, the upload settings for files is probably different
than for "regular" requests, so consider putting pages that upload files
into their own sub-folder with their own web.config.

!I would like to limit the user to upload at the maximum 1 meg of file

Iy's very simple...

In web.config :

<httpRuntime maxRequestLengt h="1024"/>
Nov 19 '07 #6
Hmmm... a bit nitpicky, but true.

I say nitpicky because I've been trying to figure out what an http request larger than
1MB looks like, other than an uploaded file...and can't come up with a valid example.

However, for comprehensivene ss sake, ( just in case a request is made which isn't
an uploaded file but is larger than 1MB ) the following web.config entry would cover all bases :

<configuratio n>
<location path="UploadPag e.aspx">
<httpRuntime maxRequestLengt h="1024"/>
</location>
</configuration>

Notice that the entry can be located in the root web.config.
A separate web.config is not needed.

If the upload aspx is in a different directory, including the path will do fine :

<location path="/directory/UploadPage.aspx ">


Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== ========
"Scott Roberts" <sr******@no.sp am.here-webworks-software.comwro te in message
news:u2******** ********@TK2MSF TNGP05.phx.gbl. ..
It should be noted that this entry will limit the size of all HTTP requests for all pages controlled by that
web.config. You can, however, put the "upload file" page in its own sub-folder and put a web.config in that folder
with the appropriate settings. For example, you might also want to adjust the timeout value to allow for slow uploads,
etc.

I guess my point is, the upload settings for files is probably different than for "regular" requests, so consider
putting pages that upload files into their own sub-folder with their own web.config.

>!I would like to limit the user to upload at the maximum 1 meg of file

Iy's very simple...

In web.config :

<httpRuntime maxRequestLengt h="1024"/>


Nov 19 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
5671
by: Joey C. | last post by:
Hello, I'm designing a small "briefcase" program that will allow me to quickly upload, download, and delete files in a briefcase. The only real things that I have left to do are to design a method for checking if the file exists, preventing it from overwriting files from other directories, and setting a user-configurable maximum limit on the...
2
2661
by: Jacky Kwok | last post by:
Dear all: I know how to use the "Application_Error" in "Global.asax" to catch the exception and display my own error message page. However, I found "Application_Error" cannot handle the error of "Maximum request length exceeded" (in my case, actually too large upload file size, I know how to modify the "maxRequestLength" to change the...
13
4289
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I...
2
4224
by: cmay | last post by:
I have changed my config files to set the limit for files being uploaded to 30 MB, but every now and then someone tries to upload a file larger than this. All I want, is to be able to trap the error and tell the user what happened. I can trap the error in the page_error (Page.Error) event, and I believe I was also trapping it at the...
4
4458
by: Matt Jensen | last post by:
Howdy I've got a rather strange issue occuring. I used forms based .NET authentication, although I'm also setting some session variables when people login. However, I've found when people use one of my webform pages which includes a button that pops up a window where you can upload files, if you upload files in this popup window, it...
2
9477
by: Lloyd Dupont | last post by:
I'm experimenting with an upload file page. I have a few HtmlInputFile on it. While testing it, I selected a 12MBfile, click "upload". I was think I am safe as (at last in the code) I don't upload file bigger than 1MB. At the top of my request there is a module where I access the request and while querying a parameter: string var =...
3
4921
by: J055 | last post by:
Hi How do I tell the user he has tried to upload a file which is too big... 1. when the httpRuntime.maxRequestLength has been exceeded and 2. when the uploaded file is under then httpRuntime.maxRequestLength For point 1. it would be good to at least display a nice error page. IE seems to just display a blank page.
7
3173
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file" name="file_1" size=46 /><input type=submit /> so, after adding a few files, the input fields look like this:
2
5235
by: skyy | last post by:
Hi.. i am doing some uploading of files using CGI with perl script.. the $CGI::POST_MAX is used to limit the maximum size of the upload file. Did anyone know what is the maximum size that i can set for $CGI::POST_MAX? and thus the maximum upload size for file upload... Thanks!
0
7703
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7618
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7678
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7982
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6286
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
1
2116
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1226
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.