Upload Image and display on User Profile page in ASP.Net

Last Reply on Jan 08, 2014 07:38 AM By Azim

Posted on Jan 08, 2014 03:21 AM

Hi all,

I am making a Human resource Management system in which i have to make  employee profiles, there is a page in which i am entering employee name and uploading a rofile picture and i want the next page to show that image on a left corner of every employee...after clicking on the submit button of the previous page please help !!!

Posted on Jan 08, 2014 07:38 AM

Here i have stored the image in folder and also saving the image path in Session. When page is redirected to second page i am checking if session is having values or not if its having the values then i am asssigning it to ImageUrl of Image control.

First.HTML:

<form id="form1" runat="server">
    <div>
        <asp:TextBox ID="txtName" runat="server" />
        <asp:FileUpload ID="fuDemo" runat="server" />
        <asp:Button ID="btnSubmit" runat="server" OnClick="SaveDetails" Text="Submit" />
    </div>
    </form>

C#:

protected void SaveDetails(object sender, EventArgs e)
    {
        if (this.fuDemo.HasFile)
        {
            fuDemo.SaveAs(Server.MapPath("~/Images/" + this.fuDemo.FileName));
            string fileName = Path.GetFileName(this.fuDemo.PostedFile.FileName);
            Session["ImagePath"] = "Images/" + fileName;

            //Some code to insert values in DataBase
            
            Response.Redirect("Page2.aspx");
        }
    }

Second.HTML:

<form id="form1" runat="server">
    <div>
        Welcome
        <br />
        <asp:Image ID="imgEmployeeImage" runat="server" />
    </div>
    </form>

C#:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Session["ImagePath"] != null)
            {
                this.imgEmployeeImage.ImageUrl = Session["ImagePath"].ToString();
            }
        }
    }

Thank You.