Dany
Dany

Reputation: 2174

how to find the number of bytes in a file?

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.

Upvotes: 9

Views: 13271

Answers (2)

Ani
Ani

Reputation: 113402

Use the FileStream.Length Property.

Gets the length in bytes of the stream.

Upvotes: 9

Yuck
Yuck

Reputation: 50835

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

new FileInfo(filename).Length;

Upvotes: 13

Related Questions