When I use FileInfo to return the size of a file for me, it is returned in bytes. The code is simple enough.
FileInfo fi = new FileInfo(filePath);
The code then returns 16599774 bytes
for the file in question.
I then convert it to Megabyte by using the following code in an extension method.
return (bytes > 0) ? (bytes / 1024f) / 1024f : bytes;
I return the MB
size as follows:
I see that the size returned is 15,8 MB. When I look at the file properties however, I see this:
When I view the file in Windows Explorer, I see a different size again
My question is this:
1. Why the difference in file sizes between 15.8 MB
and 16 599 774 bytes
that I am seeing in code and in the file properties? Does it have to do with the data types? The bytes being long
and the MB being double
2. Why is the file size in Windows Explorer different again at 16 211 KB
I understand why there is a difference between Size and Size on disk, but not between bytes and MB.