Click here to Skip to main content
14,599,201 members
Rate this:
Please Sign up or sign in to vote.
Code in Data Access

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



Code in Controller



[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);

               //da.SaveFileName(entity);
           }
           catch (Exception ex)
           {
               throw ex;
           }

       }

       return View();
   }




COde in Views

@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" />
  
}




Here I am able to store the files in the folder i have given but how to store the file name in database.
Need Help
thanks in advance
Posted
Updated 3-Mar-15 23:36pm
v2

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

what does this stored procedure : spnotaryfiles

look like in the SQL database?, your code is calling that and giving it parameters..

if you've ripped the code off elsewhere you will have to recreate the stored procedure in your database to do the job you want...

https://msdn.microsoft.com/en-gb/library/ms345415.aspx[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100