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(); } } }
[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(); }
@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" /> }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)