Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
80 views
in Technique[技术] by (71.8m points)

javascript - Html5 asp.net upload file, the collection is always empty. What wrong?

I try to upload file but the collection in empty. I have a custom button of <input type="file" generated server side.

I use this simple plugin https://github.com/MicheleBertoli/jquery-html5-uploader because I want a simple button to upload only one file.

$("#fileinput").html5Uploader({
    name: "foo",
    postUrl: "/Upload/UploadAvatar.aspx"
});

Server side I have a .aspx page

Public Class UploadAvatar
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            UploadFile(sender, e)
        End If
    End Sub

    Protected Sub UploadFile(ByVal sender As Object, ByVal e As EventArgs)
        Try
            Dim fileCollection As HttpFileCollection = Request.Files

            For i As Integer = 0 To fileCollection.Count - 1

                Dim upload As HttpPostedFile = fileCollection(i)

                Dim filename As String = "/contents/avatars/" & fileCollection(i).FileName
                upload.SaveAs(Server.MapPath(filename))
            Next

        Catch ex As Exception
            ErrorLog(ex.Message, ex.StackTrace)
        End Try
    End Sub

End Class

The problem is fileCollection.Count is always empty, 0 file.

I tried to implement the first answer of this article Upload file using asp.net webservice but then problem is same.

What wrong?

Thank you

question from:https://stackoverflow.com/questions/65650865/html5-asp-net-upload-file-the-collection-is-always-empty-what-wrong

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...