FileUpload.HasFile一直返回fasle
网页上:
<asp:FileUpload ID="ImportFile" runat="server" /> <asp:Button ID="ImportButton" runat="server" Text="确定" OnClick="ImportButton_Click" />
CodeBehind:
if (ImportFile.HasFile) { string fileName = ImportFile.FileName; string fileExtension =System.IO.Path.GetExtension(fileName); }
HasFile一直返回是false,不知道什么原因最后这样子解决就行了:
<asp:UpdatePanel runat="server"> <ContentTemplate> <asp:FileUpload ID="ImportFile" runat="server" /> <asp:Button ID="ImportButton" runat="server" Text="确定" OnClick="ImportButton_Click" /> </ContentTemplate> <Triggers> <asp:PostBackTrigger ControlID="ImportButton" /> </Triggers> </asp:UpdatePanel>