Requesting Files from asp.net Page

Viewed 51

I have a Asp.net page from which you are able to upload a picture that I need in code-behind to process and upload. Now if I try to fetch all uploaded files with Request.Files i get a count of 0. If i check with javascript then it does tell me there is a file so how can i get that File in Code-behind?

Asp.net Code

<div class="custom-file">
   <input type="file" ID="FileUploadPictureStudent" class="custom-file-input"
   aria-describedby="FileUploadPictureStudent"name="FileUploadPictureStudent" runat="server"
   onchange="fileUploadhandeler(this);" />
   <asp:Label runat="server" class="custom-file-label" for="FileUploadPictureStudent" Text="Choose file" ID="Fileuploadhelper"></asp:Label>
</div>

Vb.Net Code

Dim HelperLabel = Request.Files.Count.ToString()

Output page is 0

Output Javascript with Command document.getElementById('FormViewAddStudent_FileUploadPictureStudent').files in the console

FileList {0: File, length: 1, item: function} = $1

thanks in advance

1 Answers

As per my comment, the OP has confirmed they are trying to use the file upload within an <asp:UpdatePanel>.

Unfortunately this doesn't work, as the UpdatePanel uses AJAX to transfer data, and files cannot be part of that for browser security reasons.

Your main option is to make the page do a full post-back when uploading the file (using a <Triggers><asp:PostBackTrigger>), although I fully understand if that would not make a great UI.

Another option would be to have the file-upload in a separate .aspx file and have that display onscreen via an <iframe>... although again, this comes with a number of disadvantages.

Related