views:

24

answers:

2

I've an html file with the below markup:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
<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>

I have a handler (ashx) file to handle the upload which goes like this:

<%@ 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

When I am working with the html page, I select a file and do a submit, I get a response like this:

EncType = multipart/form-data; boundary=---------------------------7d9232a130656
File Count = 0

I was expecting the file count to be 1 here but it is 0...what is wrong?

+1  A: 

Try giving a name to your input tag:

<input type="file" name="fileToUpload" />
Darin Dimitrov
So I will get a similar error with other web engines like php, ruby, etc...?
deostroll
Yes. It's nothing to do with the server-side, any browser will always omit unnamed fields from a submission.
bobince
+1  A: 

You don't have a name attribute on your file <input>:

<input type="file" name="myFile"/><br />
Greg

related questions