public static string SetBytes(byte[] bytes, bool fromFile)
{
try
{
if (fromFile) { bytes = System.IO.File.ReadAllBytes(Encoding.Default.GetString(bytes)); }
if (bytes.Length >= 1073741824)
{
return String.Format(Convert.ToString(bytes.Length / 1024 / 1024 / 1024), "#0.00") + " GB";
}
else if (bytes.Length >= 1048576)
{
return String.Format(Convert.ToString(bytes.Length / 1024 / 1024), "#0.00") + " MB";
}
else if (bytes.Length >= 1024)
{
return String.Format(Convert.ToString(bytes.Length / 1024), "#0.00") + " KB";
}
else if (bytes.Length < 1024)
{
return bytes.Length + " Bytes";
}
return "0 Bytes";
}
catch (Exception)
{
return "Error retrieving file size";
}
}