Click here to Skip to main content
15,896,259 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is what happens when I click submit button

C#
if (btn_add.Text == "Submit")
       {
           string BracketSuspensionType = Convert.ToString(txt_BracketSuspensionType.Text.Trim());
           string PoleTypeID = Convert.ToString(dd_PoleTypeID.SelectedValue.Trim());
           string Status = chk_Active.Checked ? "True" :"False" ;
           System.Collections.Hashtable ht = (System.Collections.Hashtable)Session["UserDetails"];
           Int64 UsrId = (Int64)ht["UserID"];
           string CreatedBy = UsrId.ToString();
           //string CreatedOn = (DateTime.Now);
           string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);
           fileuploadimages.SaveAs(Server.MapPath("~/Images/" + filename));
           SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["valmont"].ToString());
           con.Open();
           SqlCommand cmd = new SqlCommand("Insert into DEF_BRACKET_ACCESSORIES_MST(BracketSuspensionType,PoleTypeID,Status,CreatedBy,CreatedOn,ImagePath) values(@BracketSuspensionType,@PoleTypeID,Status,@CreatedBy,@CreatedOn,@ImagePath)", con);

           cmd.Parameters.AddWithValue("@BracketSuspensionType", BracketSuspensionType);
           cmd.Parameters.AddWithValue("@PoleTypeID", PoleTypeID);
           cmd.Parameters.AddWithValue("@Status", Status);
           cmd.Parameters.AddWithValue("@CreatedBy", CreatedBy);
           //cmd.Parameters.AddWithValue("@CreatedOn", CreatedOn);
           cmd.Parameters.AddWithValue("@ImagePath", "Images/" + filename);


           cmd.ExecuteNonQuery();
           con.Close();


Error - An exception of type 'System.NullReferenceException' occurred in App_Web_vbsffejd.dll but was not handled in user code

Additional information: Object reference not set to an instance of an object.

Error on Line-
C#
string filename = Path.GetFileName(fileuploadimages.PostedFile.FileName);


Please suggest
Posted
Comments
Suvendu Shekhar Giri 19-Aug-15 4:15am    
The error seems to be more relevent to this line of code
fileuploadimages.SaveAs(Server.MapPath("~/Images/" + filename))
Make sure that "Image" folder path is correct.

You can get the detailed exception and stack trace by putting a breakpoint and try debugging it.

To show the acustomized message for the exception you need to handle the code. Try putting a try..catch.. around this code block.

what your "fileuploadimages.PostedFile" returns seems its null? Check it.
 
Share this answer
 
v2
check whether you have file to save in database
C#
if (btn_add.Text == "Submit" && fileuploadimages.PostedFile !=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