I tried to search for the problem in the internet and I see everyone is asking about the problem for FileUpload control inside the UpdatePanel. First of all, I am not using an UpdatePanel. Below is my code:
HTML
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" method="post" runat="server" enctype="multipart/form-data">
<div>
<asp:FileUpload ID="fuImport" runat="server" />
<asp:Button ID="btnImport" runat="server" Text="Import" />
</div>
</form>
</body>
</html>
Code Behind
Protected Sub btnImport_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnImport.Click
If (fuImport.HasFile) Then
fuImport.SaveAs(My.Settings.FileImportPath & Path.GetFileName(fuImport.FileName))
End If
End Sub
I see that fuImport.HasFile is False, but fuImport.FileName gives just the file name. For e.g., if I choose c:1.txt, it gives just "1.txt".
Can anybody let me know why fuImport.HasFile is False though I have chosen a file?
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
I found the answer. The txt file I was uploading was empty. I edited the text file and then saved by typing something in it. I could not find this anywhere mentioned in the msdn or I am not sure whether I was looking at a wrong place. The suggestion by Kasys in this post helped me.
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