Asp.net Upload File Hasfile Always False
- Re: FileUpload.HasFile is always false Mar 19, 2009 04:07 PM| jamesewelch| LINK I've tried coding it that way (it was the way that I initially started but when I ran into these problems, I tried to reduce the number of methods, functions, pointers, etc.).
- File Upload control HasFile always false, name is always Empty String, no update panel used. I have a Details View that has a file upload field in it. When I fill out the information and upload a file (I have tried multiple files ranging from 9k to 6.8MB) all of the information (text fields) submit fine, but the uploaded file is always returning a false when I check the HasFile and always returns String.Empty when I check the file name.
Then I check if myFileUploadControl.HasFile property to see if there exists a file and if there does upload the file then continue with the code. The issue is when I click this 'Update' button.HasFile always returns false even though I can see the text string of the path in the fileuploadcontrol textbox (the standard one next to the browse button).
I have a Details View that has a file upload field in it. When I fill out the information and upload a file (I have tried multiple files ranging from 9k to 6.8MB) all of the information (text fields) submit fine, but the uploaded file is always returning a false when I check the HasFile and always returns String.Empty when I check the file name.
Am I doing something wrong? The details view is in a Panel and Not an Update Panel

Code Behind:
EDITI added a Page_Load call and it looks as if the page is posting back when I click the Auto Generated Update Button for the DetailsView. This postback is probably clearing out my FileUpload field. Any ideas on how to get around it?
Edit #2 I have now put an update panel around the DetailsView and set the postback trigger the DetailsView (see below) and it still is not working, it seems to be clearing the upload control prior to submitting.
Gridview Code as requested
a few bound fields are after this (first name, last name, etc)
4 Answers

Everyone, Thanks for all of the help but I figured it out. I had to set the Page.Form.Enctype = 'multipart/form-data
.
Asp Net Core Upload File
Here is the code for it to work!
Asp.net File Upload
Simon MartinI'm sorry if this is a dumb answer but I usually use on gridviews the selectedindexchanging to capture current row values. Have you tried that instead of the selectedindexchanged?
AndresAndresAsp File Upload Code
Asp Upload File To Server
Make sure you only have one <form>
on the same page.