Hi,
Please refer below code.
HTML
<div>
<asp:FileUpload ID="fu1" runat="server" />
<asp:Button ID="btnUpload" Text="Upload" runat="server" OnClick="Upload" />
<asp:Label ID="lblFileName" runat="server" />
<br />
<asp:Button Text="Postback" runat="server" />
</div>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
Session["File"] = null;
}
else
{
if (Session["File"] != null)
{
HttpPostedFile file = (Session["File"] as HttpPostedFile);
string FileName = file.FileName;
lblFileName.Text = FileName;
}
}
}
protected void Upload(object sender, EventArgs e)
{
if (fu1.HasFile)
{
Session["File"] = fu1.PostedFile;
lblFileName.Text = fu1.PostedFile.FileName;
}
else
{
Session["File"] = null;
lblFileName.Text = string.Empty;
}
}
Screenshot