Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to find the number of bytes in a file?

Tags:

c#

file

byte

size

i am making application in C#. Here i want to find out the number of bytes in particular file. Here i am using code as

using(FileStream fs=new FileStream(filename,FileMode.Open,FileAccess.Read))
{
    //Here i want to find the number of Bytes.
    //Some more code.
}

Please help me.Thanks in advance.

like image 873
Dany Avatar asked Feb 27 '12 12:02

Dany


1 Answers

You can use the FileInfo class to get its length in bytes (as an Int64):

new FileInfo(filename).Length;
like image 83
Yuck Avatar answered Sep 21 '22 12:09

Yuck