Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
I want to get the size of a file in aspx file upload control..can anyone help me?
Posted 31-Jan-13 20:11pm
Comments
hemantrautela at 1-Feb-13 1:42am
   
why not your search it first yourself...
 
A very beginner question, which solution is already on web...
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

fileUpload1.FileBytes.Length
will give you size in bytes
 
Example
int sizeinbytes=fileUpload1.FileBytes.Length;
 
also
 
you can try
 
int sizeinbytes= FileUpload1.PostedFile.ContentLength;
 
Updated to display size in user friendly manner:
 
string[] sizes = { "B", "KB", "MB", "GB" };
double sizeinbytes=fileUpload1.FileBytes.Length;
int order = 0;
while (sizeinbytes>= 1024 && order + 1 < sizes.Length) {
    order++;
    sizeinbytes= sizeinbytes/1024;
}
 
// Adjust the format string to your preferences. For example "{0:0.#}{1}" would
// show a single decimal place, and no space.
string result = String.Format("{0:0.##} {1}", sizeinbytes, sizes[order]);
 
[Edit - Just brought the OPs two answers into one.]
If you want to get file size through javascript,
then check this solution
 
File size detection[^]
  Permalink  
v8
Comments
Maruthiram_99 at 1-Feb-13 1:18am
   
Do we need to send any arguments with it??can u explain clearly??
Santhosh Kumar J at 1-Feb-13 1:20am
   
this property will give you length..no arguments required. Like this
int sizeinbytes=fileUpload1.FileBytes.Length;
Maruthiram_99 at 1-Feb-13 1:31am
   
If we want the exact size of the file i.e in KB or MB the file is in...How to get it??
Santhosh Kumar J at 1-Feb-13 1:36am
   
updated the solution.please check
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

int imageSize = myFileUploadControl.PostedFile.ContentLength;
 
Thanks
  Permalink  
Comments
Maruthiram_99 at 1-Feb-13 1:31am
   
If we want the exact size of the file i.e in KB or MB the file is in...How to get it??
AshishChaudha at 1-Feb-13 2:14am
   
Please update your question, what exactly you need to resolve..
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

content length = FileUpload1.PostedFile.ContentLength;
 
file name legth = FileUpload1.FileName.Length;
 
where FileUpload1 is a file upload control name..
 
...
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 11 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100