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

Home Posts Topics Members FAQ

check file size before upload

hi all,

In asp.net 2.0 there is a limit on file size upload of 4MB. I know this
limit can be increased in web.config file.
Is there any way to check the file size before upload ?
if user is trying to upload file size more than 4MB then just display a
message that file size is too big and can't be uploaded.

thanks
Jul 27 '06 #1
3 30193
You can find HttpPostedFile object in FileUpload control.

Such as,
HttpPostedFile MyFile;
int FileLen;
System.IO.Strea m MyStream;

MyFileCollectio n = Request.Files;
MyFile = MyFileCollectio n[0];

FileLen = MyFile.ContentL ength;

Now, you can check file length and display some messages to alert user.

Sincerely,
simida

puja wrote:
hi all,

In asp.net 2.0 there is a limit on file size upload of 4MB. I know this
limit can be increased in web.config file.
Is there any way to check the file size before upload ?
if user is trying to upload file size more than 4MB then just display a
message that file size is too big and can't be uploaded.

thanks
Jul 28 '06 #2
thanks a lot

I got it solved using contentLength property. :)
"simida" <yo**********@g mail.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.com.. .
You can find HttpPostedFile object in FileUpload control.

Such as,
HttpPostedFile MyFile;
int FileLen;
System.IO.Strea m MyStream;

MyFileCollectio n = Request.Files;
MyFile = MyFileCollectio n[0];

FileLen = MyFile.ContentL ength;

Now, you can check file length and display some messages to alert user.

Sincerely,
simida

puja wrote:
>hi all,

In asp.net 2.0 there is a limit on file size upload of 4MB. I know this
limit can be increased in web.config file.
Is there any way to check the file size before upload ?
if user is trying to upload file size more than 4MB then just display a
message that file size is too big and can't be uploaded.

thanks

Jul 28 '06 #3
Can youplease explain where you have included this code? 'Cos fo all
postback event, the file starts upload before checking the size.

I use ASP.Net version 1.1 and is there any way to check the file size
before uploading (though Javascript)?

Thanks

Gowthami

simida wrote:
You can find HttpPostedFile object in FileUpload control.

Such as,
HttpPostedFile MyFile;
int FileLen;
System.IO.Strea m MyStream;

MyFileCollectio n = Request.Files;
MyFile = MyFileCollectio n[0];

FileLen = MyFile.ContentL ength;

Now, you can check file length and display some messages to alert user.

Sincerely,
simida

puja wrote:
hi all,

In asp.net 2.0 there is a limit on file size upload of 4MB. I know this
limit can be increased in web.config file.
Is there any way to check the file size before upload ?
if user is trying to upload file size more than 4MB then just display a
message that file size is too big and can't be uploaded.

thanks
Aug 25 '06 #4

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

Similar topics

2
5470
by: tgundeck | last post by:
Does anyone know how I can check the file size of photos or any file type in JavaScript? I'm allowing users to store photos in my web page using the input type = file tag, but need to limit the photo size to 1 meg. I would like to check the file size in JavaScript on the page, instead of on the server. Anyone know how I can check the file...
1
1497
by: Poppy | last post by:
I have written some code which uploads a file. Before I upload the file I would like to check on the file size. If its below a certain limit I want to upload it else present the user with an error message. Any Ideas ?
4
2593
by: lawrence | last post by:
Using <INPUT type"file" runat="server"> to upload a file. When the file size is too large I get a "page cannot be display" error. Thats cool I'm down with that. But is there a way to check for file size (client or server side), so that error doesn't occur? Thanks --Dietrich
6
3136
by: nicholas | last post by:
when I upload a file, I can set in my code not to save it if the file size is too large. But then the user has allready been waiting a few minutes to upload his file, as this can only be controlled once it is uploaded. I would like to say to the user the file is too large before it uploads it. any ideas? thx -- using vb.net on asp.net...
6
194105
by: monki_sf | last post by:
Was wondering if anyone knew of way to validate an images file size using javascript - i.e keeping the upload to say 500k. I've seen scripts to validate the dimensions - but nothing for the actual file size.
3
13124
by: Jefferis NoSpamme | last post by:
Hello all, I'm trying to limit the file size to 1 meg on upload of image files and I am trying a script from javascript internet, but it is giving me errors on IE ² is null or not an object ³ and isn¹t checking the file size or preventing the upload. ERROR IS <<<<Œthis.form.uploadfile.value² is null or not an object on this line:
13
4790
by: marfola | last post by:
I’m trying to find the file size using javascript, before it get uploaded into the server using the following Javascript (I don’t want to use ActiveX because of compatibility problem). function imageSize (pathField, previewName) { var str = ''; var path = pathField.value; document.src =...
6
1947
by: gyap88 | last post by:
hello, is there a command that returns the file size of a specific file as an integer
3
8252
Frinavale
by: Frinavale | last post by:
Hi there! I'm hoping that someone knows how to check the size of a file before it is uploaded to the server using JavaScript. I have seen suggested solutions using an ActiveX control to check the file size; however, I'm not happy with this solution because my application is designed to work in multiple browsers and ActiveX is limited to...
0
7614
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...
0
7924
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7676
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
6284
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
5513
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...
0
5219
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3642
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1221
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
938
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.