Code snippet that takes in a long (normally from FileInfo.Length) and returns a clean string for display.
private string FormatSize(long fileSize)
{
if (fileSize < 1024)
{
return string.Format("{0:N0} B", fileSize);
}
else if (fileSize < 1024*1024)
{
return string.Format("{0:N0} KB", fileSize/1024);
}
else
{
return string.Format("{0:N1} MB", fileSize/(1024*1024));
}
}