尽管触发了与表单和按钮单击相关的方法,但我的 fileupload 不会将值传递给字符串,我是否在做明显错误的事情(或者一般来说只是错误的)?
我是否需要将处理程序附加到文件上传
这是一些示例源代码,请注意,它是项目中唯一的代码,我没有对其他任何地方的按钮或文件上传进行任何定义:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Button_Click()
Dim FileUpload1 As New FileUpload()
Dim X As String = FileUpload1.FileName
Response.Write(X)
End Sub
End Class
和形式:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Test.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:FileUpload ID="FileUpload1" runat="server" />
<asp:Button ID="Button1" runat="server" OnClick="Button_Click" text="Submit"/>
<%-- <input type="file" />--%>
</form>
</body>
</html>
在尝试 FileUpload.HasFile 之后,似乎我不仅无法获得文件名(在下面的答案中向我描述),而且当文件与之关联时,FileUpload.HasFile 什么也不是,有什么原因吗为了这?
Protected Sub Button_Click()
Dim FileUpload1 As New FileUpload()
'Dim X As String = FileUpload1.FileName
'Response.Write(X)
If (FileUpload1.HasFile) Then
' Do Something
' SaveFile(FileUpload1.PostedFile)
Else
End If
End Sub