views:

71

answers:

2

Please can you tell me the units measured by InputFile.PostedFile.ContentLength . I need to make sure the file is less than 500k.

Thanks.

+1  A: 

It's bytes.

http://msdn.microsoft.com/en-us/library/system.web.httppostedfile.contentlength.aspx

HttpPostedFile.ContentLength

Gets the size of an uploaded file, in bytes.

Dan Dumitru
+1  A: 

Unit of measurement = Byte.

1 Kilobyte (kB) = 2ˆ10 Byte = 1024 Bytes

Sample code testing for a file size of 15 KB:

const int maxFileLength = 15360; // 15KB = 1024 * 15

if(PictureFile.PostedFile.ContentLength > maxFileLength) {

  MyResult.Text = String.Format("Your post has a size of {0:#,##0} bytes which
  exceeded the limit of {0:#,##0} bytes. Please upload a smaller file.",
  PictureFile.ContentLength, maxFileLength);
}
else
{
  // Save the file here
  MyResult.Text = "Thank you for posting."
}

In your case, as you want the file to be less than 500 KB, you should have this:

const int maxFileLength = 512000; // 500KB = 500 * 1024
Leniel Macaferi