Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Code in Data Access

C#
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



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

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

       }

       return View();
   }




COde in Views

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




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

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[^]
 
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