Solved

Limit file to i MegaByte

Posted on 2013-02-03
5
187 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

Technology Partners: 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

Suggested Solutions

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

685 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