Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Check If Text File Has Content

I am building a C# WPF Browser App (my C# skills are quite rusty).

I have a button that I want to have change color depending on if a text document has anything in it. IE: Color is Green if there is any text in it, or Red if it is empty.

Can someone please push me off in the right direction. Thank you.

like image 357
The Woo Avatar asked Feb 11 '11 02:02

The Woo


1 Answers

Take a look at System.IO.FileInfo

FileInfo f = new FileInfo( "<file path>" );
if( f.Length > 0 ) 
  // Color button green
else 
  // Color button red

Note that if you keep f around and plan to check it again later, you will have to call f.Refresh() to ensure it has the latest information.

like image 120
Chris Hogan Avatar answered Sep 26 '22 02:09

Chris Hogan