Click here to Skip to main content
15,888,527 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi guys am back with another question.. I have a file name in DB and when i display the name i must show the filename+ size of it. The file path is inside my project itself.. So how can i get the filesize from the path so that i can display the file with name and as size...



Say the filename is Img.jpg and size is 5kb i must show like this Img.jpg(5kb)
Posted
Comments
[no name] 4-Jul-12 7:53am    
FileInfo.Length

use System.IO.FileInfo and length property of it to get size of file.
 
Share this answer
 
Comments
Manas Bhardwaj 4-Jul-12 8:00am    
ditto +5!
You can use FileInfo.Length. It gives file size in bytes.

FileInfo fileInfo = new FileInfo("Input.txt");
Console.Write(string.Format("{0} ({1}B)", fileInfo.Name, fileInfo.Length));
 
Share this answer
 
Comments
Arjun Menon U.K 4-Jul-12 8:05am    
Manas what if ihave show it interms of KB or MB?
Manas Bhardwaj 4-Jul-12 8:08am    
Shouldn't be difficult:
1024 Bytes = 1 KiloByte
1024 KiloBytes = 1 MegaByte
Paul E Davies 4-Jul-12 8:13am    
Well there are 1024 bytes in 1 KB and 1024 KB in 1 MB so some simple division.

Too slow, that will teach me to do some work :)
Arjun Menon U.K 4-Jul-12 8:22am    
ok i know the math but just asking if there is any explicit conversion or so :P Cheers Bro
For file size use the FileInfo.Length Property[^].

More information generally on Common I/O Tasks[^].
 
Share this answer
 
Hi ...

Try the below code;

C#
FileUpload1.SaveAs(Server.MapPath("uploads\\").ToString () + FileUpload1.FileName);
           double filelength = FileUpload1.FileContent.Length;
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900