【发布时间】:2009-08-28 12:05:31
【问题描述】:
当我尝试发布文件时,它返回错误,即没有附加文件。有人能看出这有什么问题吗?或者是什么原因造成的。
<form id="Form1" enctype="multipart/form-data" method="post" runat="server">
<asp:FileUpload ID="fileUpload" runat="server" />
<asp:Button ID="cmdSubmitApplication" runat="server" Text="Button" />
</form>
Protected Sub cmdSubmitApplication_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSubmitApplication.Click
If Me.fileUpload.PostedFile Is Nothing Then
Response.Write("You must specify file to upload!")
Else
Try
Dim strExt As String = Path.GetExtension(Me.fileUpload.PostedFile.FileName)
If strExt.ToLower() = ".doc" Then
Dim savedFile As String
savedFile = Path.GetFileName(Me.fileUpload.PostedFile.FileName)
Me.fileUpload.PostedFile.SaveAs(Server.MapPath("cvs\") & savedFile)
Response.Write("File Uploaded Successfully")
Else
Response.Write("Only Image Files are Allowed")
End If
Catch exp As Exception
Response.Write(exp.Message)
End Try
End If
End Sub
【问题讨论】:
-
它一直告诉我“您必须指定要上传的文件!”
-
澄清一下,这是 ASP.NET 2.0?
-
您是否在 web.config 中指定了上传大小上限?
标签: asp.net vb.net file-upload