This code should be in yourfilename.aspx.vb .
Const maxFileSize As Integer = 1048576
Dim intDocFileLength As Integer = Me.AttachmentFile.PostedFile.ContentLength
If intDocFileLength > maxFileSize Then
Label1.Text = “File size exceeds the limit of 1MB.”
Exit Sub
End If
*AttachmentFile is the name of the fileupload control ID.