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?
解决方案
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.
我试图寻找在互联网上的问题,我看到每个人都在问的UpdatePanel内FileUpload控件的问题。首先,我不使用一个UpdatePanel。下面是我的code:
HTML
&LT;头=服务器&GT; &LT;标题&GT;&LT; /标题&GT; &LT; /头&GT; &LT;身体GT; &LT;表ID =Form1的方法=邮报=服务器ENCTYPE =的multipart / form-data的&GT; &LT; DIV&GT; &LT; ASP:文件上传ID =fuImport=服务器/&GT; &LT; ASP:按钮的ID =btnImport=服务器文本=输入/&GT; &LT; / DIV&GT; &LT; /表及GT; &LT; /身体GT; &LT; / HTML&GT;
code背后
保护小组btnImport_Click(BYVAL发件人为对象,BYVAL E上EventArgs的)把手btnImport.Click 如果(fuImport.HasFile)然后 fuImport.SaveAs(My.Settings.FileImportPath&安培; Path.GetFileName(fuImport.FileName)) 万一 结束小组
我看到fuImport.HasFile是假的,但fuImport.FileName只给出文件名。对于例如,如果我选择 C:\ 1.txt的,它给刚的1.txt。
任何人都可以让我知道为什么fuImport.HasFile是假,虽然我已经选择了一个文件?
解决方案
我找到了答案。 txt文件,我上传是空的。我编辑的文本文件,然后通过键入它的东西保存。我找不到在MSDN提到这在任何地方或我不知道我是否一直在寻找在错误的地方。通过Kasys在的建议这篇文章帮助了我。