Home > Mobile >  How to check the file size inside my C# program?
How to check the file size inside my C# program?

Time:03-20

How do I check inside my C# program that if the size of my program is not greater than 100mb for example, to not run or to auto-destroy itself when someone run it again ?

I tried to search everywhere, but I can't seem to find anything relatable.

CodePudding user response:

// Get the information about a file
FileInfo fi = new FileInfo(file);
// Print the file size to console
Console.WriteLine($"File size: {fi.Length} bytes");

CodePudding user response:

Get the current executable file name, then use the FileInfo class and it's Property Length, that returns the file size in bytes:

FileInfo fi = new FileInfo(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
//fi.Length <= 104857600 // that is 1024*1024*100 bytes
  •  Tags:  
  • c#
  • Related