Asp.net Upload File Hasfile Always False
hi all here the code then i will explain my question:-
every time i track the code it says that (fileUpload.HasFile)=false
and never sees the code after that, then jumps to the else statment and thats the rest of the code
Dec 30, 2014 - Inorder to retain the selection during PostBack you should enable the view state property as below asp:FileUpload ID='fuBrowseXMLFile'. Oct 24, 2008 - FileUpload inside UpdatePanel. The browse to open file is success but when read the HasFile propoerty, always return false. Is there any.
3 Answers
Check if you'r using a UpdatePanel, if so then in Page.Init do something like this:
The reason why fileUpload.HasFiles = False
is that by the time that code is reached, the file stream has been closed inside of the HandleUploadFile Subroutine.
'this using statement closes the original input stream and there removes it'from the FileUpload
I think it might be that you write you file to the directory and in doing that it clears out the fileupload form. This is happening before you run your if statement. Try moving your if/else above the 'handleuploadedfile()' function. This should ensure that you can check the upload form before the system writes the file and removes it from the upload form.
I am creating a visual web-part for my SharePoint 2013 environment. I am using asp:FileUpload
control(fuBrowseXMLFile
) in this web-part for uploading files to a document library. I have a button Save
to initiate the process of uploading the file.
After deploying the code, i try to run it in Debug
mode. I found that after clicking the Save
button, when the debugger hits the following line of code,
fuBrowseXMLFile.HasFile
returns FALSE
. Whereas the file is selected in the control.
While searching for a solution, I came across lot of articles. But, unfortunately most of them talk with reference to UpdatePanel
. I am not using UpdatePanel
here.
I understand that it has to do something with Postback
. But, I am not sure what would exactly resolve my problem.
1 Answer
Inorder to retain the selection during PostBack
you should enable the view state property as below
Asp Upload File To Server
Rest Approach