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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…