Wednesday, 12 March 2014

How to get file length in C#

How to get file length in C#
using System;
using System.IO;
class GetFileLength
{
static void Main()
{
const string strFileName = "Myfile.txt";
FileInfo objfileInfo = new FileInfo(strFileName);
long s1 = objfileInfo.Length;
File.AppendAllText(strFileName, " Add new information....");
FileInfo f2 = new FileInfo(strFileName);
long s2 = f2.Length;
Console.WriteLine("Before and after: " + s1.ToString() + "" + s2.ToString());
long change = s2 - s1;
Console.WriteLine("Size increase: " + change.ToString());
}
}