ExtensionMethod.NET Home of 875 C#, Visual Basic, F# and Javascript extension methods

FileSize

Get the file size of a given filename.

Source

public static long FileSize(this string filePath)
{
	long bytes = 0;

	try
	{
		System.IO.FileInfo oFileInfo = new System.IO.FileInfo(filePath);
		bytes = oFileInfo.Length;    
	}
	catch{}
	return bytes;
}

Example

string path = @"D:\WWW\Proj\web.config";
Console.WriteLine("File Size is: {0} bytes.", path.FileSize());

Author: Earljon Hidalgo

Submitted on: 26 mrt 2008

Language: C#

Type: System.Int64

Views: 5171