我有一个带有以下标记的html文件:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
<title>Upload Page</title>
</head>
<body>
<form id="frmUpload" action="UploadHandler.ashx" method="post" enctype="multipart/form-data">
<input type="file" /><br />
<br />
<input id="Submit1" type="submit" value="Submit" />
</form>
</body>
</html>
我有一个处理程序(ashx)文件来处理上传,如下所示:
<%@ WebHandler Language="VB" Class="UploadHandler" %>
Imports System
Imports System.Web
Imports System.Diagnostics
Public Class UploadHandler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
Dim str As String
str = "EncType = " & context.Request.ContentType
str &= vbCrLf
str &= "File Count = " & context.Request.Files.Count
context.Response.ContentType = "text/plain"
context.Response.Write(str)
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
End Class
当我使用html页面时,我选择一个文件并进行提交,我得到这样的回复:
EncType = multipart/form-data; boundary=---------------------------7d9232a130656
File Count = 0
我原本希望文件计数在这里是1,但它是0 ......出了什么问题?
答案 0 :(得分:1)
尝试为输入标记命名:
<input type="file" name="fileToUpload" />
答案 1 :(得分:1)
您的文件name
上没有<input>
属性:
<input type="file" name="myFile"/><br />