Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
code in data Accesslayer

C#
public class DataAccess
    {
        //FilesEntity files = new FilesEntity();
        public void SaveFileName(string fileName)
        {
            string cs = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString;
            using (SqlConnection con = new SqlConnection(cs))
            {
                SqlCommand cmd = new SqlCommand("spnotaryfiles", con);
                cmd.Parameters.AddWithValue("@Filename", fileName);
                cmd.CommandType = CommandType.StoredProcedure;
                con.Open();
                cmd.ExecuteNonQuery();
            }
        }
    }


Code in Action Controller

C#
[HttpPost]
      public ActionResult Index(HttpPostedFileBase file)
      {
          if(file != null && file.ContentLength > 0)
          {
              try
              {
                  var fileName = Path.GetFileName(file.FileName);
                  var path = Path.Combine(Server.MapPath("~/Images/"), fileName);
                  file.SaveAs(path);
                  entity.filename = fileName;
                  da.SaveFileName(fileName);
              }
              catch (Exception ex)
              {
                  throw ex;
              }

          }

          return View();
      }



Code in View

HTML
@using (Html.BeginForm("Index", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
{

    <input type="file" name="file" /><br />
    <input type="submit" name="Submit" id="Submit" value="Upload" />
  
}

Getting Exception that saying
HTML
@using (Html.BeginForm("Index", "File", FormMethod.Post, new { enctype = "multipart/form-data" }))
{

    <input type="file" name="file" /><br />
    <input type="submit" name="Submit" id="Submit" value="Upload" />
  
}

please help me to how to pass parameter to storedprocedure from controller
Posted
Comments
Kornfeld Eliyahu Peter 2-Mar-15 5:49am    
You didn't posted the error message but the code twice! Please fix it...

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