Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
heyy..I have a file upload control....All I wanted is, I need the file name of the file that I select through file upload controls..and that file name is displayed in a label....(when I selected through the file upload controls)....

here found a code ..but it is not changed when another file name is selected ...



C#
if (Session["fluNoticeUpload"] == null && fluNoticeUpload.HasFile)
             {
                 Session["fluNoticeUpload"] = fluNoticeUpload;
                 lblfile.Text = fluNoticeUpload.FileName;
             }
             // Next time submit and Session has values but FileUpload is Blank
             // Return the values from session to FileUpload
             else if (Session["fluNoticeUpload"] != null && (!fluNoticeUpload.HasFile))
             {
                 fluNoticeUpload = (FileUpload)Session["fluNoticeUpload"];
                 lblfile.Text = fluNoticeUpload.FileName;
             }
             // Now there could be another sictution when Session has File but user want to change the file
             // In this case we have to change the file in session object
             else if (fluNoticeUpload.HasFile)
             {
                 Session["fluNoticeUpload"] = fluNoticeUpload;
                 lblfile.Text = fluNoticeUpload.FileName;
             }
Posted

1 solution

Hi,
I have added a FileUpload, lable and button control in the aspx page. Below code implemented in the button click and things are working fine as you expected.

C#
protected void Button1_Click(object sender, EventArgs e)
    {
        Label1.Text = FileUpload1.FileName;
    }


Use the FileName property of the fileupload control, where ever you want.

Best Regards
Muthuraja
 
Share this answer
 

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