check file size before upload

P

puja

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
 
S

simida

You can find HttpPostedFile object in FileUpload control.

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

MyFileCollection = Request.Files;
MyFile = MyFileCollection[0];

FileLen = MyFile.ContentLength;

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

Sincerely,
simida
 
P

puja

thanks a lot

I got it solved using contentLength property. :)


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

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

MyFileCollection = Request.Files;
MyFile = MyFileCollection[0];

FileLen = MyFile.ContentLength;

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

Sincerely,
simida
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
 
S

Saiashok

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
You can find HttpPostedFile object in FileUpload control.

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

MyFileCollection = Request.Files;
MyFile = MyFileCollection[0];

FileLen = MyFile.ContentLength;

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

Sincerely,
simida
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
 

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

Top