Click here to Skip to main content
15,894,017 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

I have added a file upload option in my form. But when I check Fileupload.HasFile it give false even when I select the file.
Code Below:

XML
<asp:FileUpload
                                        ID="Resume_File"
                                        runat="server"
                                        BackColor="DodgerBlue"
                                        ForeColor="AliceBlue" />
                                        <asp:Button runat="server" id="Up_Resume_File" text="Upload"
                                            onclick="Up_Resume_File_Click"/><br /><br />
                                        <asp:Label runat="server" id="StatusLabel" text="Upload status: " />

C#
protected void Up_Resume_File_Click(object sender, EventArgs e)
    {
        if (Resume_File.HasFile)
        {
            StatusLabel.Text = "Yes";
        }
        else
        {
            StatusLabel.Text = "No";
        }
    }


Kindly guide me on this, where I am gone wrong.
Posted

Try This out:
C#
protected void Up_Resume_File_Click(object sender, EventArgs e)
{
    if (Resume_File.PostedFile.FileName!= string.Empty)
    {
        StatusLabel.Text = Yes;
    }
    else
    {
        StatusLabel.Text = No;
    }
}
 
Share this answer
 
v2
Your code is correct only. As I guessed, you have taken your file upload control inside the update panel(You can see the same situation here[^]). Remove the update panel and check it again.

Alternative solution:
Add a trigger for UpdatePanel:
ASP.NET
<triggers>
   <asp:postbacktrigger controlid="btnCertificateUpload" />
</triggers>

This will force a postback when the upload button is clicked.

After that add the below line to the Page_Load:
C#
Page.Form.Attributes.Add("enctype", "multipart/form-data");



Hope it helps.!
--Amit
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900