R
rn5a
I am giving users the option to upload files from their hard disk to
the server but only those files will be uploaded whose size is less
tha or equal to 1 MB.
I am using the ASP.NET FileUpload control to design the interface.
This is the code:
<script runat="server">
Sub Page_Load(.....)
If (Page.IsPostBack) Then
If (fudFile1.FileName <> "") Then
If (fudFile1.FileBytes.Length / 1048576 > 1) Then
lblMessage.Text = "File size cannot exceed 1 MB"
Else
fudFile1.SaveAs(Server.MapPath(fudFile1.FileName))
lblMessage.Text = "File uploaded"
End If
End If
End If
End Sub
</script>
<form runat="server">
<asp:FileUpload ID="fudFile1" runat="server"/><br><br>
<asp:Button ID="btnUpload" Text="UPLOAD FILE" runat="server"/>
<asp:Label ID="lblMessage" runat="server"/>
</form>
Now what I find is if I try to upload a file whose size is greater
than 1 MB but less than or equal to 4 MB, then, as expected, the Label
renders the message "File size cannot exceed 1 MB" but if the file
size exceeds 4 MB, then the Label doesn't render the "File size cannot
exceed 1 MB" message.
Instead, IE just renders the omnipresent "The page cannot be
displayed" page with the error "Cannot find server or DNS Error" at
the very end of the page.
Why isn't the Label displaying the "File size cannot exceed 1 MB"
message when the file size is greater than 1 MB but less than or equal
to 4 MB? How do I ensure that even if the file size exceeds 4 MB,
users are still shown the Label with the message "File size cannot
exceed 1 MB"?
the server but only those files will be uploaded whose size is less
tha or equal to 1 MB.
I am using the ASP.NET FileUpload control to design the interface.
This is the code:
<script runat="server">
Sub Page_Load(.....)
If (Page.IsPostBack) Then
If (fudFile1.FileName <> "") Then
If (fudFile1.FileBytes.Length / 1048576 > 1) Then
lblMessage.Text = "File size cannot exceed 1 MB"
Else
fudFile1.SaveAs(Server.MapPath(fudFile1.FileName))
lblMessage.Text = "File uploaded"
End If
End If
End If
End Sub
</script>
<form runat="server">
<asp:FileUpload ID="fudFile1" runat="server"/><br><br>
<asp:Button ID="btnUpload" Text="UPLOAD FILE" runat="server"/>
<asp:Label ID="lblMessage" runat="server"/>
</form>
Now what I find is if I try to upload a file whose size is greater
than 1 MB but less than or equal to 4 MB, then, as expected, the Label
renders the message "File size cannot exceed 1 MB" but if the file
size exceeds 4 MB, then the Label doesn't render the "File size cannot
exceed 1 MB" message.
Instead, IE just renders the omnipresent "The page cannot be
displayed" page with the error "Cannot find server or DNS Error" at
the very end of the page.
Why isn't the Label displaying the "File size cannot exceed 1 MB"
message when the file size is greater than 1 MB but less than or equal
to 4 MB? How do I ensure that even if the file size exceeds 4 MB,
users are still shown the Label with the message "File size cannot
exceed 1 MB"?