Waqar Malik Waqar Malik - 2 months ago 6
C# Question

I want to show 3Mb in my return message, gets value from Web.config

I have code down below that returns if your file name is to large, please upload a file which is less than 3145728 MB.

yield return new ValidationResult(string.Format("File \"{0}\" size is too large , please upload a file which is less than {1} MB", (fl.FileName), (maxfilesize), new[] { "allowedFiletypes" }));


Instead I want the error message to show 3 MB and not 3145728MB,

below is my Web.config

<add key="maximumfilesize" value="3145728" />


cheers

Answer

3145728 is in Bytes, not MB

Have a look at this code snippet ((maxfilesize/ 1024f)/ 1024f)

yield return new ValidationResult(string.Format("File \"{0}\" size is too large , please upload a file which is less than {1} MB", (fl.FileName), ((maxfilesize/ 1024f)/ 1024f), new[] { "allowedFiletypes" }));