Click here to Skip to main content
12,405,303 members (64,376 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C# ASP.NET
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:

<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: " />
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 9-Oct-12 0:17am
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Try This out:
protected void Up_Resume_File_Click(object sender, EventArgs e)
{
    if (Resume_File.PostedFile.FileName!= string.Empty)
    {
        StatusLabel.Text = Yes;
    }
    else
    {
        StatusLabel.Text = No;
    }
}
  Permalink  
v2
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 3

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:
<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:
Page.Form.Attributes.Add("enctype", "multipart/form-data");


Hope it helps.!
--Amit
  Permalink  
v3

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160721.1 | Last Updated 9 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100