Been banging my head against the wall and Google try to find the answer to my problem.
When the below IF statement executes is appears to be running completely through the IF and ELSE statements.
if (IsPostBack)
{
Boolean bFileOK = false;
if (fulReagentImg.HasFile)
{
String sFileExtension = System.IO.Path.GetExtension(fulReagentImg.FileName).ToLower();
String sFileExtensionLabel = sFileExtension;
lblFileExtension.Text = sFileExtensionLabel;
String[] allowedExtensions = { ".gif", ".png", ".jpeg", ".jpg" };
for (int i = 0; i < allowedExtensions.Length; i++)
{
if (sFileExtension == allowedExtensions[i])
{
bFileOK = true;
}
else
{
lblException.Text = "Can only upload .gif, .png, .jpeg, .jpg";
lblException.CssClass = "red";
}
}
Any ideas why it’s not stopping with bFileOK = true?
Because your sFileExtension is a single extension, not all four of the allowed extensions. This means that even if the sFileExtension is ONE of the allowed extensions, it will still not be the other three, so no matter what, your else statement will get hit.