Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Limit file to i MegaByte

Posted on 2013-02-03
5
Medium Priority
?
190 Views
Last Modified: 2013-02-05
I have a file upload page and I want to limit the file size to 1 MegaByte. I did this but looks like it's not correct because i have a file of 2404KB that I cant upload. CurrentLength is in Bytes
 if (file.ContentLength > 1048576)
                {
                   lmsg.Text = "Maximum file size is 1 MegaByte";
                   return;
                }


What value should I use?
0
Comment
Question by:Camillia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 27

Accepted Solution

by:
Shaun Kline earned 2000 total points
ID: 38849809
A megabyte is 1024 kilobytes which is 1048576 bytes. Your algorithm is working correctly. If you want allow 2404 kilobytes, you will need to change 1048576 to 2461696.
0
 
LVL 7

Author Comment

by:Camillia
ID: 38849812
Is there a "standard" file size in ASP.Net that should be allowed for a user to upload? or is it all depends on the application/business logic?
0
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 38849825
There is no standard. It is as you said, dependent on the business logic/need.
0
 
LVL 29

Expert Comment

by:Kumaraswamy R
ID: 38849971
try

long[] numbersToConvert = { 162345, 32183, -54000, Int64.MaxValue/2 };
int newNumber;
foreach (long number in numbersToConvert)
{
   if (number >= Int32.MinValue && number <= Int32.MaxValue)
   {
      newNumber = Convert.ToInt32(number);
      Responce.write("Successfully converted {0} to an Int32.",
                        newNumber);
   }
   else
   {
      Responce.write("Unable to convert {0} to an Int32.", number);
   }
}
0
 
LVL 7

Author Comment

by:Camillia
ID: 38851014
What does that code do?
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question