Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is the logic. Insert is working fine for all other fields. BUt Imagepath is taking null.

C#
if (btn_add.Text == "Submit")
        {
           
               
                

                BracketAccessoriesEntity.BracketSuspensionType = Convert.ToString(txt_BracketSuspensionType.Text.Trim());
                BracketAccessoriesEntity.PoleTypeID = Convert.ToInt64(dd_PoleTypeID.SelectedValue.Trim());
                BracketAccessoriesEntity.AccessoryID = Convert.ToInt32(ViewState["Id"]);
                BracketAccessoriesEntity.Status = chk_Active.Checked;
                System.Collections.Hashtable ht = (System.Collections.Hashtable)Session["UserDetails"];
                Int64 UsrId = (Int64)ht["UserID"];
                BracketAccessoriesEntity.UpdatedBy = UsrId;
                BracketAccessoriesEntity.UpdatedOn = (DateTime.Now);
                string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
                fileuploadimages.SaveAs(Server.MapPath("~/Images/Bracket Type/" + filename));
                BracketAccessoriesEntity.ImagePath = "~/Images/Bracket Type/" + filename;

                try
                {
                    string result = logic.InsertData(BracketAccessoriesEntity);
                    if (result == "SUCCESS")
                    {
                        string jScript = "<script>alert ('" + "Record Updated Successfully" + "')</script>";
                        ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "starScript", jScript, false);
                        clear();
                       
                        BindGrid();
                    }


I know I am making mistake with Image path. Can you please suggest what should I write in these lines because maybe mistake is here.
C#
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
fileuploadimages.SaveAs(Server.MapPath("~/Images/Bracket Type/" + filename));
BracketAccessoriesEntity.ImagePath = "~/Images/Bracket Type/" + filename;
Posted
Updated 25-Aug-15 2:43am
v4
Comments
Juan de Villiers 26-Aug-15 13:51pm    
Have you tried using the Server.MapPath when assigning the ImagePath?

1 solution

Make sure that the line
C#
Path.GetFileName(fileuploadimages.PostedFile.FileName);

is not returning NULL.
 
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