C# Newbie: Getting file size of text file?

  • Thread starter Thread starter Mashao Rakgole
  • Start date Start date
M

Mashao Rakgole

In C#,

How does one get the file size of a given text file?

BR
Mashao
 
You can use System.IO.FileInfo

example:
System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"c:\getmysize.txt");
// write file length in bytes to textbox1
this.textBox1.Text = fileInfo.Length.ToString();


Hope this helps,
Erik
 
Hi,


You can get the size of any file by using FileInfo.Length
 
Mashao said:
In C#,

How does one get the file size of a given text file?

To get the size in bytes, you use the Length property of the FileInfo
class, as others already have mentioned.

If you want to know the size in characters, you have to read the file
and decode the bytes into characters to find out the size.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top