FileUpload1.HasFile是假 [英] FileUpload1.HasFile is False

查看:653
本文介绍了FileUpload1.HasFile是假的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图寻找在互联网上的问题,我看到每个人都在问的UpdatePanel内FileUpload控件的问题。首先,我不使用一个UpdatePanel。下面是我的code:

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背后

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

我看到fuImport.HasFile是假的,但fuImport.FileName只给出文件名。对于例如,如果我选择 C:\\ 1.txt的,它给刚的1.txt
任何人都可以让我知道为什么fuImport.HasFile是假,虽然我已经选择了一个文件?

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?

推荐答案

我找到了答案。 txt文件,我上传是空的。我编辑的文本文件,然后通过键入它的东西保存。我找不到在MSDN提到这在任何地方或我不知道我是否一直在寻找在错误的地方。通过Kasys在的建议这篇文章帮助了我。

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.

这篇关于FileUpload1.HasFile是假的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆