Protected Sub AddFileButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
If FileUploader.HasFile Then
Dim fileSize = FileUploader.PostedFile.ContentLength
If fileSize > 1048576 Then
Info.Text = "This file exceeds the allowed file size (1 MB). Please resize the image or select another file."
Return
ElseIf fileSize < 1 Then
Info.Text = "This file does not have enough content to send. Please choose another file."
Return
Try
Dim extension = System.IO.Path.GetExtension(FileUploader.FileName)
Dim uniqueFileName = System.Guid.NewGuid.ToString() & extension
FileUploader.SaveAs("\\filepath\" & FileUploader.FileName)
Catch ex As Exception
Info.Text = "ERROR: " & ex.Message.ToString()
End Try
End If
End If
End Sub
For some reason it is not hitting the If fileSize > 1048576 Then
or the Else If fileSize < 1 Then
. It is just doing the Try and Catch and displaying an error if it exceeds the 1mb limit I have defined in my web.config.
Is there a syntax or logic error I am not seeing?