Hi @umesh kumar ,
You only need to use one of the methods in the picture above.
The file name needs to be included in the Server.MapPath method.
string fname = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/EmpImages/" + fname));
Since EmpImages/
is already included in the EmpImgPath
parameter, the source code of the image link should be as follows:
<asp:Image ID="Image1" runat="server" ImageAlign="Middle" ImageUrl='<%#Eval("EmpImgPath","~/{0}")%>'/>
ALL code
protected void Button1_Click(object sender, EventArgs e)
{
if (FileUpload1.HasFiles)
{
//if (FileUpload1.PostedFile != null)
//{
string fname = Path.GetFileName(FileUpload1.PostedFile.FileName);
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/EmpImages/" + fname));
con.Open();
SqlCommand cmd = new SqlCommand("insert into [dbo].[Reg] (Id,Name,EmailId,Mobile,Password,EmpImgPath ) values(@Id,@Name,@EmailId,@Mobile,@Password,@EmpImgPath)", con);
cmd.Parameters.AddWithValue("Id", TextBox1.Text);
cmd.Parameters.AddWithValue("Name", TextBox2.Text);
cmd.Parameters.AddWithValue("EmailId", TextBox3.Text);
cmd.Parameters.AddWithValue("Mobile", TextBox4.Text);
cmd.Parameters.AddWithValue("Password", TextBox5.Text);
cmd.Parameters.AddWithValue("EmpImgName", fname);
cmd.Parameters.AddWithValue("EmpImgPath", "EmpImages/" + fname);
cmd.ExecuteNonQuery();
Response.Write("you have sucessfully registered");
Response.Redirect("Login.aspx");
}
Best regards,
Lan Huang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.