views:

107

answers:

1

I have a input of type file and when i try to do a Request.files when the input is wrapped in an update panel...it always returns an empty httpfilecollection. Why???

This is the codebehind: (At HttpContext.Current.Request.Files...its always 0 for the count.)

 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
    Dim uploads As HttpFileCollection
    uploads = HttpContext.Current.Request.Files

    For i As Integer = 0 To (uploads.Count - 1)

        If (uploads(i).ContentLength > 0) Then
            Dim c As String = System.IO.Path.GetFileName(uploads(i).FileName)

            Try
                uploads(i).SaveAs("C:\UploadedUserFiles\" + c)
                Span1.InnerHtml = "File Uploaded Sucessfully."
            Catch Exp As Exception
                Span1.InnerHtml = "Some Error occured."
            End Try

        End If

    Next i

End Sub

This example comes from the ASP.Net website...but my application is very similar.

+2  A: 

Check this out File upload and update panel

alejandrobog
Im using type of file control though: <input id="File2" type="file" /> Not the asp type of control...any difference?
Sean P
Also, this deals with when you have to update the file control. I need to update everything else... and an asynchronous updatepanel doesn't work... the file collection returns 0
Sean P
The issue is the same: the <input type="file"> control simply does not work inside an UpdatePanel. As the article says, for security reasons, Javascript is not allowed to access the file so it cannot be posted back as part of the UpdatePanel.
Dean Harding