class Demo
{
static void Main()
{
var mydocs = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string filepath = Path.Combine(mydocs, "test.txt");
if (File.Exists(filepath))
{
FileStream fileStream = File.Open(filepath, FileMode.Open);
Console.WriteLine($"File size in bytes: {fileStream.Length}");
Console.WriteLine($"File size in Mega bytes: {(double)fileStream.Length / 1024}");
}
var pictures = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
filepath = Path.Combine(pictures, "ganga.jpg");
if (File.Exists(filepath))
{
FileStream fileStream = File.Open(filepath, FileMode.Open);
Console.WriteLine($"File size in bytes: {fileStream.Length}");
Console.WriteLine($"File size in Mega bytes: {(double)fileStream.Length / 1024}");
}
}
}
Wednesday, June 17, 2026
C# How to get FIle size of a file
The following code shows how to get the size of a file in bytes and megabytes. The Length property of FileStream helps to get the file size.
Subscribe to:
Post Comments (Atom)
Hot Topics
-
In previous post , we learnt basic introduction to SQL Server . In this post we will learn about SSMS (SQL Server Management Studio) softwar...
-
In the previous post we have learnt about SSMS (SQL Server Management Studio) and how to connect with a SQL Server instance. In this post w...
-
By Ajeet Kumar RADAR CHART In radar chart, the categorical variable is displayed as spikes radiating from a central point. The values o...
No comments:
Post a Comment