Lớp FileInfo có thuộc tính Length trả về kích thước file tính bằng byte.
Ví dụ
using System;
using System.Linq;
using System.IO;
class Program
{
static void Main()
{
FileInfo file = new FileInfo(@"D:\new");
long res = file.Length;
Console.WriteLine("Số byte: " + res);
}
}
Kết quả
3259244
Lưu ý: Đảm bảo file tồn tại, ném FileNotFoundException nếu không.