Solved

Limit file to i MegaByte

Posted on 2013-02-03
5
181 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
  • 2
  • 2
5 Comments
 
LVL 26

Accepted Solution

by:
Shaun Kline earned 500 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 26

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now