Requesting Files from asp.net Page

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x