[英]Visual Basic Max File Size Error
Protected Sub AddFileButton_Click(ByVal sender As Object, _
ByVal e As System.EventArgs)
Dim fileSize = FileUploader.PostedFile.ContentLength
If FileUploader.HasFile Then
Try
Dim extension = System.IO.Path.GetExtension(FileUploader.FileName)
Dim uniqueFileName = System.Guid.NewGuid.ToString() & extension
FileUploader.SaveAs("\\path\" & FileUploader.FileName)
Catch ex As Exception
Info.Text = "ERROR: " & ex.Message.ToString()
End Try
Else
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
End If
End If
End Sub
嘿,团队! 我有一个快速的问题。 我正在尝试处理最大文件大小错误。
如果文件太小,它将起作用。 但是,如果文件太大(1mb),则会出现错误
'/'应用程序中的Blockquote服务器错误
超过了最大请求长度。
描述 :在执行当前Web请求期间发生未处理的异常。 请查看堆栈跟踪,以获取有关错误及其在代码中起源的更多信息。
我将如何越过错误屏幕并告诉用户上传较小的文件?
您对If FileUploader.HasFile Then
else
语句没有任何意义。 如果没有要上传的文件,如何检查文件大小? 将嵌套的if语句( If fileSize > 1048576 Then
)移到主要的IF语句中。 像这样:
If FileUploader.HasFile Then
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
Else
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.