【发布时间】:2015-05-22 15:45:41
【问题描述】:
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)我会收到错误
块引用 “/”应用程序中的服务器错误
已超出最大请求长度。
说明:在执行当前网络请求期间发生未处理的异常。请查看堆栈跟踪以获取有关错误及其源自代码的位置的更多信息。
我怎样才能越过错误屏幕并告诉用户上传一个较小的文件?
【问题讨论】:
标签: asp.net .net vb.net file-upload error-handling